2016-08-12 1 views
0

나는 수가 26 인, 데이터베이스 서버에 오류를 연결할 수없는 것 SQL Server 관리 개체 (SMO) 사용하여 응용 프로그램을 가지고 :SMO를 사용하여 SQL Server에 연결할 수없는 이유는 무엇입니까?

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

그러나이 유일한 것 같다을 그 데이터베이스에 연결할 수 없습니다. 문제없이 작동 아래 모두를 사용하여 데이터베이스에 연결 :

  • SQL Server Management Studio를 PowerShell을

  • System.Data.SqlClient.SqlConnection
  • ODBC
  • SQLPS 모듈을 SQLCMD
  • 이것은이다 코드를 사용하고 있는데, 데이터베이스에 액세스하려고하면 예외가 발생하고 모든 값은 볼 수 있습니다. t가 있어야한다 :

    Server = new SMO.Server(
        new ServerConnection(
         new SqlConnectionStringBuilder 
         { 
          DataSource = ServerName, 
          InitialCatalog = DatabaseName, 
          IntegratedSecurity = true 
         }.ConnectionString)); 
    
    Database = Server.Databases[DatabaseName]; 
    

    내가 발견 한 유일한 것은 내가 내 SQL Server 인스턴스의 sqlcmd -L 전혀 실행하지 않을 때 표시한다는 것입니다. 나는 기본적으로 같은 것을 볼 것으로 예상 :

    Servers: 
        SQL2008 
        SQL2012 
        SQL2014 
        SQL2016 
    

    을하지만 그것이 말하는 모든입니다

    Servers: 
         ;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?;*APP:AppName=?;*WSID:WorkStation ID=?; 
    
  • 답변

    0

    가 해결 RTFM과 습관의 힘을 잊는의 또 다른 케이스.

    기본적으로 생성자 Server(string)이 연결 문자열이 아닌 인스턴스 이름을 사용한다는 사실을 잊어 버렸습니다. 그래서 그것은 내 연결 문자열과 같은 이름을 가진 인스턴스에 연결하려고했습니다.

    있다하여 다른 생성자 Server(ServerConnection) 그래서 내가 무슨 짓을해야하는 것은 중 하나 이것이다 :

    Server = new SMO.Server(
        new ServerConnection(
         new SqlConnectionStringBuilder 
         { 
          DataSource = ServerName, 
          InitialCatalog = DatabaseName, 
          IntegratedSecurity = true 
         })); 
    

    또는 아주 간단하게이 :

    Server = new SMO.Server(ServerName); 
    
    관련 문제