所以这是我的代码:
Private adoConnection As System.Data.SqlClient.SqlConnection
Private adoadapterFillDSUsers As New System.Data.SqlClient.SqlDataAdapter()
Private ServerName As String = ""
Private ConnectionString As String = ""
Private Sub adoconn()
adoConnection = New System.Data.SqlClient.SqlConnection()
adoConnection.ConnectionString = DataManager.DataManager.ConnectionString
End Sub
Public Sub ContinueInit()
ReadRegistry()
Dim currRegKey As RegistryKey
Dim newRegKey As RegistryKey
currRegKey = Registry.CurrentConfig
Try
newRegKey = currRegKey.OpenSubKey("Hoh_Dev\Data")
Catch ex As Exception
Return
End Try
Try
MREZA = newRegKey.GetValue("Mreza")
ServerName = newRegKey.GetValue("ServerName")
Catch ex As Exception
Return
End Try
If MREZA = "D" Then
ConnectionString = "Data Source=" & ServerName & ";Integrated Security = SSPI;"
Else
If MREZA = "W" Then
ConnectionString = "Data Source=" & ServerName & ";Database=" & DataBaseName & ";user id=xxx;pwd=xxx;"
End If
End If
adoconn()
End Sub
自从每次我想连接到我的服务器并使用它时,我已经失去了理智:
If adoConnection.State = ConnectionState.Closed Then adoConnection.Open()
Try
DataManager.DataManager.adoCommand.ExecuteNonQuery()
Catch OpenConnectionError As System.Data.SqlClient.SqlException
End Try
我收到了这个错误:
The ConnectionString property has not been initialized.
ContinueInit
我从表单加载事件中调用sub:
Private Sub LogIn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ContinueInit()
Me.TextBox1.Focus()
Me.TransparencyKey = BackColor
Me.Button2.Visible = False
Me.Button1.Visible = False
TextBox2.PasswordChar = "*"
End Sub
代码破裂,adoConnection.Open()
这意味着我什至无法打开与服务器的连接,因此我可以执行 SQL 查询,这只会导致我没有设置好的东西。