I am trying to produce a database by remote hooking up to some SQL Server Express using Visual Studio 2008. I visit SQL Server using SQL Authentication. I'm able to do this remotely using SQL Server Management Studio Express not a problem using the following command:

CREATE DATABASE dbname ON (Title='dbname_dat', FILENAME='C:folderdbname.mdf') LOG ON (Title='dbname_log', FILENAME='C:folderdbname.ldf')

However, after i make use of the same line during my code, I recieve the next error:

CREATE DATABASE permission refused in database 'master'.

Error number is 262 and sophistication number is 14. My connection string is:

server=servernamedatabase=mastertrusted_connection=yesPooling=false

Can anybody help?

Well, the mistake message informs you what's wrong, does not it? The consumer you utilize to log into via C# does not plenty of permission to complete CREATE claims.

You appear to utilize a different user to sign in via SQL Server Management Studio rather than sign in via C#. Would you log in to the SQL server via Home windows Authentication and via SQL Server authentication in C#? Or possibly in Management Studio you've selected another database to execute the sql statement? Look into the combobox for that database the script uses.

This really is too apparent, but look at your permissions around the server. Are you currently a sysadmin or perhaps a dbcreator?

Also, look at your user qualifications. Your connection string states trusted_connection=yes however you say that you're signing in using SQL Server authentication. Which are you currently or for anyone who is using?

I'd claim that your qualifications aren't being passed right through to the database. If this sounds like an internet site, this might happen for several reasons:

  • You do not have impersonation switched on
  • You've fundamental authentication switched on in IIS..

Check this out article on MSDN about How to Access SQL Server Using Windows Integrated Security for detailed instructions about establishing integrated security, or change to a set SQL Server account.

Try modifying your connection string to something like this (Note the consumer and Pwd configurations):

tmpConn.ConnectionString = "SERVER = " + DBParam.ServerName + "; DATABASE = master; User ID = sa; Pwd = sa";

The sa account might have the privileges to get this done command.