Home > Software engineering >  At the same time two database connection problem
At the same time two database connection problem

Time:12-22

 Public PublicStr As String 
Public PublicStr1 As String
Private con As New ADODB. Connection
Private rs As New ADODB. You
Private rs1 As New ADODB. You
Dim STR As String

Public Sub Main ()
Additional database
'On the Error Resume Next
Con. The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa "
Con. Open 'Open database connection
Set the rs=New ADODB. You 'start additional database
STR="EXEC sp_attach_db @ dbname=N 'xi2009' @ filename1=N '" + App. Path +" \ DataSource \ xi9_Data MDF "+"', @ filename2=N '" + App. Path + "\ DataSource \ xi2009_Log LDF" + "' "
Set the rs=con. The Execute (STR)
Con. Close 'Close the database connection
PublicStr="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa; Initial Catalog=xi2009; Data Source=tu "user - 20150115

Con. The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa "
Con. Open 'Open database connection
Set rs1=New ADODB. You 'start additional database
STR="EXEC sp_attach_db @ dbname=N 'xi2016' @ filename1=N '" + App. Path +" \ DataSource \ xi2016_Data MDF "+"', @ filename2=N '" + App. Path + "\ DataSource \ xi2016_Log LDF" + "' "
The Set rs1=con. The Execute (STR)
Con. Close 'Close the database connection
PublicStr1="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa; Initial Catalog=xi2016; Data Source=tu "user - 20150115
Frm_star. Show
End Sub

Private Sub Command1_Click ()
Adodc1. The ConnectionString=PublicStr1
Adodc1. RecordSource="delete from WY_JCXX"
Adodc1. Refresh
Adodc1. The ConnectionString=PublicStr
Adodc1. RecordSource="insert into xi2016.. WY_JCXX select material codes, material name, specifications, lead time from xi2009. J. XT_TC_Material where Left (material code, 1)=1
"Adodc1. Refresh
The Set DataGrid1. The DataSource=Adodc1
DataGrid1. Refresh
StatusBar1. SimpleText=DataGrid1. ApproxCount
End Sub

SQL Server has two databases, XI2009 and XI2016
Adodc1. Refresh, every time a problem here, "
"Do not allow the operation object is closed,"

Real-time error "3704"
Application error definition or object definition

CodePudding user response:

Someone to help me have a look at it, thank you!

CodePudding user response:

 Public PublicStr0 As String 
Public PublicStr1 As String
Private cn0 As New ADODB. Connection
Private cn1 As New ADODB. Connection
Private rs0 As New ADODB. You
Private rs1 As New ADODB. You
Dim STR As String

Public Sub Main ()
Additional database
''On the Error Resume Next
Cn0. The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa "
Cn0. Open 'Open database connection
STR="EXEC sp_attach_db @ dbname=N 'xi2009' @ filename1=N '" + App. Path +" \ DataSource \ xi9_Data MDF "+"', @ filename2=N '" + App. Path + "\ DataSource \ xi2009_Log LDF" + "' "
The Set rs0=cn0. Execute (STR)
PublicStr0="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa; Initial Catalog=xi2009; Data Source=tu "user - 20150115

Cn1. The ConnectionString="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa "
Cn1. Open 'Open database connection
STR="EXEC sp_attach_db @ dbname=N 'xi2016' @ filename1=N '" + App. Path +" \ DataSource \ xi2016_Data MDF "+"', @ filename2=N '" + App. Path + "\ DataSource \ xi2016_Log LDF" + "' "
The Set rs1=cn1. Execute (STR)
PublicStr1="Provider=SQLOLEDB. 1; Persist Security Info=False; User ID=sa; Password=sa; Initial Catalog=xi2016; Data Source=tu "user - 20150115
Frm_star. Show
End Sub
Private Sub Form_Unload (Cancel As Integer)
Cn0. Close
Cn1. Close
End Sub
Private Sub Command1_Click ()
Adodc1. The ConnectionString=PublicStr1
Adodc1. RecordSource="delete from WY_JCXX"
Adodc1. Refresh
Adodc1. The ConnectionString=PublicStr0
Adodc1. RecordSource="insert into xi2016.. WY_JCXX select material codes, material name, specifications, lead time from xi2009. J. XT_TC_Material where Left (material code, 1)=1
"Adodc1. Refresh
The Set DataGrid1. The DataSource=Adodc1
DataGrid1. Refresh
StatusBar1. SimpleText=DataGrid1. ApproxCount
End Sub

  • Related