我用VB做了个小软件,需要根据用户选择的参数从DB2下载数据到本地,软件启动后,从数据库DSNLB01读取数据(表 NGDBALAP.TEST)成功,接着用户改变了参数,从数据库 DSNKB01读取数据(表NGDBAKA1.TEST)就报错.
软件启动后第一次读取的数据库总能成功,第二次的就失败.也就是说如果用户先从 DSNKB01读取数据(表NGDBAKA1.TEST)也能成功,之后再从数据库DSNLB01读取数据(表 NGDBALAP.TEST)就失败. 代码概括如下, 希望各位大侠解救.....多谢
Private Sub get_data_from_db2( byval schema as string,byval connectionString as string )
my_from_refresh("正在从db2下载数据......", 18)
Dim temps As String
Dim rows As Integer
Dim db2_cmd As New OleDbCommand()
Dim rd As OleDbDataReader
table_name = Main_menu.S_TABLE_USE
db2_cmd.CommandText = "SELECT * FROM “+ schema + "." + table_name
db2_cmd.Connection = New OleDbConnection(db2_connectionString)
db2_cmd.CommandType = CommandType.Text
db2_cmd.CommandTimeout = 120
Try
db2_cmd.Connection.Open()
rd = db2_cmd.ExecuteReader() ――就是执行到这里报错
While rd.Read()
rows = rows + 1
End While
rd.Close()
db2_cmd.Connection.Close()
my_from_refresh("db2数据下载成功!", 40)
Catch ex As Exception
db2_cmd.Connection.Close()
process_flag = 1
error_discript = "查询主机数据异常" + ex.ToString
End Try
End Sub
Private sub form_load()
Dim string sc as string
Dim db2_connectionString As String = "Provider=IBMDADB2;DSN=DSNLB01;User "+ _
"ID=GZZJ11;Password=1234567;Server=122.131.31.231:50000" ‘ DSN有改变
Sc = “NGDBALAP”
get_data_from_db2(Sc)----第一次调用成功
db2_connectionString="Provider=IBMDADB2;DSN=DSNKB01;User "+ _
"ID=GZZJ11;Password=1234567;Server=122.131.31.231:50000"
sc = “NGDBAKA1”
get_data_from_db2(Sc)-----报错: System.data.oledb.oledbexception:[DB2]SQL0204N --------
“NGDBAKA1.TEST”是未定义的名称. SQLSTATE = 42704
End sub