0

I am trying to create a content db from asp.net application c# hosted in share point server.

my code is

  SPWebApplication elevatedWebApp = spWeb.Site.WebApplication;
                        string serverName = "xxx\xxx";
                        string newDbName = "WSS_Content_1";
                        string username = "xxxx\\spfarm";
                        string password = "xxxxx";
                        var contentDatabase = elevatedWebApp.ContentDatabases.Add(serverName,newDbName,username,password,0,1,0);

                        contentDatabase.Update();
                        elevatedWebApp.Update();

I got this error message

Cannot connect to database master at SQL server The database might not exist, or the current user does not have permission to connect to it.

I'd appreciate any thoughts.

Thanks

2
  • Is it event receiver? Or what type of application? Under which account it is running?
    – Waqas Sarwar MVP
    Dec 22 '16 at 14:31
  • 1
    Use powershell to create web appln, content db etc entities instead of C#. is there any particular reason for creating these entities using C# Dec 23 '16 at 5:56
0

the issue is mostly with the account under which the application is running, If the application is running under non-farm account then you will get access denied.

account should need DB creator and Security admin on the SQL Server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.