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? Commented Dec 22, 2016 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# Commented Dec 23, 2016 at 5:56

1 Answer 1

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.