Tuesday, February 14, 2012

Database Create error

I am trying to create a database in my application's installation folder and it will not create because the folder does not have the permissions for the service account added as full control. I can't figure out how to get the service account name in my program so that I can add it to the folder permissions. The service name is a long name and has the computer name and the SQL server name included in it. For example: SQLServer2005MSSQLUser$<Ccmputer Name>$SQLEXPRESS. I'm assuming this pattern is always followed. I guess my question is can I query the database for this information and then use it to add the appropriate permissions to my application's install folder?

The pattern for the service account names you described is correct for the default SQL Express settings. I would like to generalize this pattern for all the 3 groups SQL Server 2005 may create on the computer:

* Sql Server group:

SQLServer2005MSSQLUser$<<machine_name>>$<<instance_name>>

* Agent group:

SQLServer2005SQLAgentUser$<<machine_name>>$<<instance_name>>

* Full text search group:

SQLServer2005MSFTEUser$<<machine_name>>$<<instance_name>>

You can use these patterns directly by inserting the machine name and SQL Server instance name (the default instance name is called MSSQLSERVER ).

An alternative method would be to use the following query:

SELECT name, sid FROM sys.server_principals WHERE name like '%SQLServer2005MSSQLUser%'

Be aware that a system administrator may drop this server principal from the server, invalidating this query to obtain the Windows service group.

I hope this information was useful. Let us know if you have any further questions or feedback.

Thanks a lot,

Raul Garcia

SDE/T

SQL Server Engine

No comments:

Post a Comment