所以这是我的代码:
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查询,这导致我只能做一些我没有设置好的东西。
答案 0 :(得分:1)
您的连接对象没有填写ConnectionString
。
不确定DataManager.DataManager是什么,但我猜你正在做一些事情,你在DataManager类中创建了一个DataManager类的共享实例,并将其称为DataManager。 (非常令人困惑)但是,我猜您需要查看此内容并逐步执行代码以查找连接字符串为空字符串的原因。