2016-11-14 59 views
0

我在使用Windows身份驗證(SSPI)爲Odbc PostgreSQL連接的uid = in連接字符串中插入值時收到異常。添加用戶名時,ODBC SSPI連接失敗

錯誤:

Connection problem: System.InvalidOperationException: The connection was not closed. The connection's current state is connecting. 
    at System.Data.ProviderBase.DbConnectionClosedConnecting.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) 
    at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) 
    at System.Data.Odbc.OdbcConnection.Open() 
    at ConsoleApplication1.Program.TestMethod(String connectionMethod) 

代碼(在程序中打開()的第一次調用,因爲拉編寫了用於測試):

try 
     { 
      using (OdbcConnection connection = new OdbcConnection(odbc_connection_string)) 
      { 
       connection.Open(); 
      } 
     } 
     catch (Exception ex) 
     { 
      System.Diagnostics.Trace.WriteLine("Connection problem: " + ex); 
      odbc = false; 
     } 

連接字符串:

odbc_connection_string = "[email protected];Driver={PostgreSQL Unicode};database=hostdb-4.2.0;server=localhost;port=5432;Trusted_Connection=yes"; 

Npgsql連接允許輸入用戶名:

npgsql_connection_string = "Server=localhost;Port=5432;Database=hostdb-4.2.0;User [email protected];Integrated Security=true;"; 
+0

嘗試在不使用'使用(.....)'的情況下發生的情況聲明OdbcConnection,然後將其打開。我想你正在使用Pwd =你的密碼 – McNets

+0

它表現出相同的行爲。 –

回答

0

我不知道爲什麼我顯示InvalidOperationException錯誤。通常我得到AccessViolationExceptions。

其中一個psqlodbc 9.3驅動程序是此問題的來源。我將psqlodbc驅動程序更改爲9.5.4,並且能夠在uid字段中輸入值。