添加用户名时,ODBC SSPI连接失败

时间:2016-11-14 22:15:00

标签: postgresql odbc windows-authentication uid sspi

我在使用Windows身份验证(SSPI)为Odbc PostgreSQL连接的连接字符串中为uid =输入值时,我会收到异常。

错误:

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)

代码(程序中第一次调用Open()因为拉出代码进行测试):

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 = "uid=bwhuggin@CCANET;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 Id=bwhuggin@CCANET;Integrated Security=true;";

1 个答案:

答案 0 :(得分:0)

我不确定为什么我出现了InvalidOperationException错误。通常我得到了AccessViolationExceptions。

其中一个psqlodbc 9.3驱动程序是此问题的根源。我将psqlodbc驱动程序更改为9.5.4,并且我能够在uid字段中输入一个值。