-1
我有这样的vb.net代码:不允许改变的ConnectionString
conn6.ConnectionString = "server=" + global_variables.web_server_ip + "; user id=" + global_variables.web_server_username + "; password=" + global_variables.web_server_password + "; database=" + global_variables.web_server_database + "; "
conn6.Open()
SQL = "select calltype from billing group by calltype "
myCommand6.Connection = conn6
myCommand6.CommandText = SQL
reader6 = myCommand6.ExecuteReader
While reader6.Read
cdr_call_type = reader6.GetString(0)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'do VoIP bit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If customerid_voip <> "" Or customerid_voip_new <> "" Then
'do customer VoIP Bit, which means getting the latest value from billing table
TextBox1.Text = "Got VoIP - " + cdr_call_type + vbCrLf + TextBox1.Text
Me.Refresh()
conn3.ConnectionString = "server=" + global_variables.web_server_ip + "; user id=" + global_variables.web_server_username + "; password=" + global_variables.web_server_password + "; database=" + global_variables.web_server_database + "; "
conn3.Open()
SQL = "select reseller_bill, customer_bill, phone, calltype, timestamp, seconds from billing where calltype = '" + reader6.GetString(0) + "' AND (source='CDR' or source='' or source='VOIP') and (company='" + customerid_voip + "' or company='" + customerid_voip_new + "') "
myCommand3.Connection = conn3
myCommand3.CommandText = SQL
reader3 = myCommand3.ExecuteReader
While reader3.Read
'do stuff here
End While
reader3.Close()
conn3.Close()
End If
End While
reader6.Close()
conn6.Close()
当我运行代码,我得到的线conn3.Open()
一个错误说:
不允许更改'ConnectionString'属性,而连接(state = Open)。
它可以在第一个循环,但是当我避开第二循环停止并显示此错误
错误消息指出在打开连接字符串时无法更改连接字符串。所以你只需要在修改它之前关闭它。 – 2014-10-28 09:22:57
我已经关闭它,使用conn3.close() – user3843997 2014-10-28 09:23:46
关闭conn6在尝试使用另一个连接之前 – NoviceProgrammer 2014-10-28 09:24:46