views:

1715

answers:

3

I'm using SQL Management Studio 2008 Express as a graphic interface to my local SQL Server 2008 Express instance, both of which I have locally only as a test and developement interface for my web projects.

I have recently grown more confident in SQL coding, and started to use some more complicated sql stuff - my latest field of exploration being triggers. However, to my great surprise I don't seem to have admin rights on my server instance, which means I can't do simple things like debugging or changing access rights.

When I try to start debugging I get a permission denied message, and I have also seen it when I try to manage permission rules to different databases. I suspect this has something to do with some option I chose when I installed the server, but as I already have several databases set up and filled with data, I have no desire to uninstall and reinstall the whole thing.

So my question is:

Is there any way to change which user account is the master admin of the server instance? If not, is there any other way to get permission rights to for example debug my triggers?

A: 

Sql Server Configuration Manager.

That will allow you to set the instance account.

However what I think you might be after is changing the database owner to the user you connect to the database with. IF you're using SSPI then this will be your logged in user, or if you are using SQL authentication this will be the user connecting inside your connection string.

Additional:

If you are debugging on Windows XP or above, and you are not the administrator (local), then you will need to be placed into the "Debugging Users" group on that system. Otherwise accessing memory or attaching a debugger to a process you don't own is a big no no.

Spence
Thanks for the reply! I have two follow-up questions: 1) If i change the instance account to my own Windows user account, will that still allow ASP.NET the access it needs to test-run my sites? 2) How do I change the database owner to be myself (that is indeed something I wish to do)? When I've tried, I've gotten the permission denied message. A Catch 22...
Tomas Lycken
Yes, provided that the ASP.Net application pool is connecting as your user.If you run ASP.Net from the debugger, that instance runs as your user.In IIS, that user is set by the "application pool" which executes your site. You can create a custom one with your user credentials, then set your website to run as that user.However, the problem is that you still will not get the access you want to your DB, as that is set by the database, not the SQL Server instance account.
Spence
Do you have administrative privileges? If you do, chexk what account you are connecting to the management studio.
Spence
I'm debugging the site on IIS using an application pool that runs on my own user account, and the SQL server seems to be running on the Network Service account, so changing that shouldn't cause any new problems. But as you say this won't solve my problem anyway... How do I check what account I'm connecting with?
Tomas Lycken
your connection string.As I said the permissions on the database are what are preventing you from doing anything, not the permissions to the sql server instance. In the SQL Server management studio, when you go through the connect dialog, is it set to windows authentication or sql authentication? Windows is your user account, SQL is internal to SQL. IF you are not the administrator you will have to get an admin to help you out.
Spence
+2  A: 

Log on to your computer as the Local Administrator account. By default, that should be a sysadmin role in MSSQL.

Using SSMS, connect to your MSSQL instance using integrated authentication. You are now a sysadmin. As a sysadmin, you can now add your normal user account to the sysadmin role:

EXEC sp_addsrvrolemember @loginame = 'PC_OR_DOMAIN\loginname', @rolename = 'sysadmin'

If you use SSPI (aka Integrated Authentication, aka not a different username and password when you start up SSMS) then just use your Windows login as the loginame. If you use Sql Server Authentication (aka, a username and password) then use the username as loginame. If you use any other loginame, an account will be created as well.

There's certainly a way to do it within the GUI - but I don't have it handy ATM to tell you how. I think it's under Security -> Logins -> Properties and some checkboxes for the various server roles.

Edit: Enabling the local admin account on Vista Also, if you are a local Administrator (your user account is listed under Local Administrators group) then - by default - you are a sysadmin. It may be worth double checking the members of the sysadmin role (SQL) and the Local Admins group (Vista).

Edit2: Turns out, SQL 2008 does not add BUILTIN\Administators any more. In that case, you need to check what you did add. That should be available via the Logins node. There is a note that you can be locked out of MSSQL Admin if you don't choose a sysadmin login. If that's the case, I'd reinstall. You can save your databases by stopping MSSQL and copying the *.MDF and *.LDF files. After reinstallation, copy them back and use sp_attach_db to reattach them.

Mark Brackett
How do I log on as the Local Admin? I run Windows Vista, and the only account I know of is my regular user account (AASLOEG\Tomas, as my computer's name is AASLOEG...). I have rights to run stuff as admin, but running SSMS as admin does not do the trick. I have tried doing what that SQL statement should do through the GUI, but I'm denied permission so far...
Tomas Lycken
Thanks for the links in your edits - although they didn't solve my problem, I did learn some other useful stuff. I ended upp moving out the db files from the mssql directory, reinstalling and making sure both the local admin group and my own user account were added to the sysadmin role. It was a hazzle, but it works now. Thanks!
Tomas Lycken
FYI, this solved my problem.
Mufasa
+1  A: 

See http://blogs.msdn.com/b/sqlexpress/archive/2010/02/23/how-to-take-ownership-of-your-local-sql-server-2008-express.aspx

Gabe
Since I don't have this problem anymore (right now) I can't verify that it works. But if it does, it is definitely a better solution than what I ended up doing! =)
Tomas Lycken