0

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

DSN configuration

user692942
  • 16,398
  • 7
  • 76
  • 175
Mr.E1987
  • 1
  • 1
  • 1
    Do you get any errors with your script? – GSerg Jun 30 '20 at 06:35
  • 1
    Did you test the connection on machine 1 or 2? You don't need the DSN on machine 2 if your app is running on machine 1. – TomC Jun 30 '20 at 06:48
  • GSerg: I get no errors at all. In fact the database kept updating when i ran he script on the local database of machine 1. – Mr.E1987 Jun 30 '20 at 09:16
  • TomC: I tested the connection on both machines. Like I said, i read somewhere here a suggestion to create the DSN on both machines – Mr.E1987 Jun 30 '20 at 09:18
  • You forgot to mention you are using Siemens WinCC, this isn’t a basic standalone VBScript. – user692942 Jun 30 '20 at 09:56
  • Lankymart: I already mentioned that I am using TIA that is running VBS. Also, I don't think there is any problem with WinCC since the script runs fine on the local machine database – Mr.E1987 Jun 30 '20 at 13:49
  • @Mr.E1987 All I'm saying is `lngValue = HMIRuntime.Tags("Tag_2").Read` is not standard VBScript syntax it's only available through a proprietary app in this case `WinCC`, so should at least be tagged to that extent. – user692942 Jun 30 '20 at 16:12
  • Lankymart: OK, got your point no problem. I just wanted to assure that the script was working fine. – Mr.E1987 Jun 30 '20 at 20:51
  • Yes, but unless those trying to help have access to WinCC than they won’t be able to reproduce the issue. In fact this is likely a network issue more than a scripting one. Have you tried using IP instead of hostname in the DSN? – user692942 Jul 01 '20 at 00:32

1 Answers1

0

Thanks for your assistance. It turns out that the problem was in the (sqlrowser) service as it was disabled.

Mr.E1987
  • 1
  • 1