I have 2 virtual machines for testing purpose.
- Machine 1 Windows 7 SP1 (Script Machine) has a SW (Siemens TIA v15 to be specific) that runs a VB script and MS SQL Management studio set up.
- Machine 2 Windows 10 (DB Machine) has MS SQL Server Standard 2019 (64-bit) and MS SQL Management studio set up on it.
Object:
I want to write data from the VB script on machine 1 into the DB of machine 2 remotely.
Procedure:
On machine 1, I created and ODBC connection under (System DSN) called TIBA_R
and gave it a SQL auth. for a user that I created under the MS Management Studio. In my VB script I have the following connection string:
Provider=MSDASQL;DSN=TIBA_R;UID=tiba_admin;PWD=asd@1234
On machine 2, I created the same identical DSN (I read that somewhere and forgive my lack of knowledge (flushing face)).
I test connection for DSN and all seems well. However when my script runs from machine 1, there is no data applied in the table of machine 2.
I tested the network between the 2 VMs through pinging and is working. I tested my VB script on a local database on machine 1 and is working fine.
Question:
How do I get the VB script on machine 1 to connect to the DB on machine 2 and apply data in the table? Is using ODBC correct for this application? What can I be doing wrong?
Note: This is a sample of my VB script if it will help. I am also attaching a photo of the configuration of the DSN
Dim objConnection
Dim strConnectionString
Dim lngValue
Dim strSQL
Dim objCommand
strConnectionString = "Provider=MSDASQL;DSN=TIBA_R;UID=tiba_admin;PWD=asd@1234;"
lngValue = HMIRuntime.Tags("Tag_2").Read
strSQL = "INSERT INTO table1 (data) VALUES (" & lngValue & ");"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
.ActiveConnection = objConnection
.CommandText = strSQL
End With
objCommand.Execute
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing