2016-04-23 80 views
0

爲什麼下面的代碼:集成安全的MySQL/VB.NET

Dim conn As MySqlConnection = 
    New MySqlConnection("server=localhost;Integrated Security=True;") 

不起作用?當我嘗試conn.open();時出現以下錯誤:Object reference not set to an instance of an object.

+0

如果不能進行身份驗證,並且不會有創建的連接。請參閱[使用Windows本地身份驗證插件](https://dev.mysql.com/doc/connector-net/en/connector-net-programming-authentication-windows-native.html) – Plutonix

回答

1

https://www.connectionstrings.com/mysql/

Use Windows authentication Server=myServerAddress;Database=myDataBase;IntegratedSecurity=yes; Uid=auth_windows; This option is available from Connector/NET version 6.4.4The Windows Native Authentication Plugin must be installed for this to work.

1

我不知道如果mysql接受集成安全性。

I M使用這一項上的MySQL,你給str_query返回DataTable的結果

Public Function mysql(ByVal str_query As String) As DataTable 
     Dim adptr As New MySqlDataAdapter 
     Dim filltab As New DataTable 
     Try 
      Using cnn As New MySqlConnection("server=" & mysql_server & ";user=" & mysql_user & ";password=" & mysql_password & ";database=" & mysql_database & ";Allow User Variables=True") 
       Using cmd As New MySqlCommand(str_query, cnn) 
        cnn.Open() 
            adptr = New MySqlDataAdapter(cmd) 
        adptr.Fill(filltab) 
        cnn.Close() 
       End Using 
      End Using 
     Catch ex As Exception 
'you can log mysql errors into a file here log(ex.ToString) 
     End Try 
     Return filltab 
    End Function 
+0

謝謝,但我需要做到這一點具有集成安全性。 – MATH000