Attach a database using SMO keep fail

I am using this SMO code to attach a database.

        Server mServer = new Server(".");

        mServer.AttachDatabase("DbName", new StringCollection { 
            "DbName.mdf", 
            "DbName_log.LDF" }, AttachOptions.None);

But I keep getting an exception

Failed to connect to server.

Any ideas?

[Changed]

Internal exception:

{"A network-related or specific instance error occurred while establishing a connection to SQL Server. The server could not be found or is unavailable. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (Provider: named pipe provider, error: 40 - Could not open connection to SQL Server) "}

+3
source share
2 answers

The error speaks for itself - SMO cannot connect to the server.

  • ?
  • ??
  • , (, ".\SQLExpress")??

:

  • MDF/LDF - . - ?

- - , . ...... - .

  • SQL Server ?

, SMO " " . ? SQL Server ( ; SQL Server> > SQL Server):

alt text

, , , ( , ).

+2

. smo. mdf ldf Visual Studio, (C:), . , db . ,

0

Source: https://habr.com/ru/post/1751043/


All Articles