SetParent Failed for Database xxx

  • I'm trying to create a database using SQL smo with C# as follows:

    ServerConnection connDst = new ServerConnection("servername\\MSSQLServer", "sa", "password");

    Server serverDst = new Server(connDst);

    Database newdb = new Database(serverDst, "MyDataBase");

    newdb.Create();

    I get the error SetParent failed for Database MyDataBase on the newdb = new Database line.

    I'm confident the login is correct because I can login on using ssms 2005 and I can create a database.

  • smjhunt (11/17/2010)


    ServerConnection connDst = new ServerConnection("servername\\MSSQLServer", "sa", "password");

    Are you using the correct Instance Name?

    servername\\MSSQLServer does not seem to be a right one.

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

  • It's the name in ()'s in the services control panel. Is that not the instance name ?

  • If the name in Services is SQL Server (MSSQLServer) then it is a default instance. Hence the instance name in the connection string would be ServerName

    If the name in Services is SQL Server (AnythingOtherThanMSSQLServer) then it is a named instance. Hence the instance in the connection string would be ServerName\AnythingOtherThanMSSQLServer

    Pradeep Adiga
    Blog: sqldbadiaries.com
    Twitter: @pradeepadiga

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply