• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1695
  • Last Modified:

VBScript open connect to port example?

Dear experts,

does anyone have a piece of example code on how to open a connection to a host:port in VBScript? I need this for a Macro in word to pull names and addresses out of a non-standard database. I can figure out how to format the response, I just need some help getting started on opening/closing the connection, sending the string, and how to put the response in a variable.

Sincerely,

Jos.
0
Azhrei1
Asked:
Azhrei1
  • 7
  • 5
2 Solutions
 
RobSampsonCommented:
Hi, perhaps you could find a similar connection string for your database from here:
http://connectionstrings.com/

Regards,

Rob.
0
 
Azhrei1Author Commented:
Hi Rob,

thanks for the comment, I didn't know about that site and it seems useful :)

But unfortunately not for this problem...this database communicates with HL7 messages (SOAP)....and it's not listed there :(

Jos.
0
 
RobSampsonCommented:
Then you could just connect to it using something like the following

Regards,

Rob.
Set objCN = CreateObject("ADODB.Connection")
strConnection = "Driver={SQL Server};Server=YourServer;Database=YourDatabase;Trusted_Connection=TRUE"
objCN.Open strConnection
strSQLQuery = "Select SomeField From SomeTable"
objRS = CreateObject("ADODB.Recordset")
Set objRS = objCN.Execute(strSQLQuery)
Do Until objRS.EOF
	WScript.Echo objRS.Fields("SomeField")
	objRS.MoveNext
Loop
objRS.Close
objCN.Close

Open in new window

0
Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

 
Azhrei1Author Commented:
crosspost? :)
0
 
RobSampsonCommented:
Is it some sort of Oracle XE database:

Oracle XE, VB6 ADO
strConnection = "Provider=OraOLEDB.Oracle;dbq=localhost:1521/XE;Database=myDataBase;User Id=myUsername;Password=myPassword;"

The 1521 is the port number.

Rob.
0
 
Azhrei1Author Commented:
No, it's actually Intersystems Cache, but in this case they dont' allow a direct connection, there is a small tool in between that will require a custom message. Hence the need for a direct TCP/IP connection to send the string it requires, and then parse what comes back. I found some ways to do a soap HTTP request, but that's not going to cut it as it's similar, but not exactly soap. I know, it's an annoying situation and I started out with saying it's not possible in VBScript, but it's always nice to surprise someone afterwards with it being possible afterall :)
0
 
RobSampsonCommented:
So how do you currently send the TCP/IP message that it requires?  Through some sort of web interface I imagine? What language?  Is it a HTTP Request header that we send via VBScript using the Microsoft.XMLHTTP object and performing a command like this:

Regards,

Rob.
0
 
RobSampsonCommented:
Or, here's a possible connection string for Intersystems Cache (as long as you have the InterSystems ODBC driver installed on the computer):
strConnection = "provider=MSDASQL.1;Extended Properties="DRIVER={InterSystems ODBC};SERVER=127.0.0.1; PORT=1972;DATABASE=JDKKR;UID=foo;PWD=bar"

Regards,

Rob.
0
 
Azhrei1Author Commented:
ok. I guess that's good to know. I don't think the team will allow the customer to access the database directly though...but who knows. You're sure there is no way to just set up a TCP connection in VBScript? Like if I'd want to telnet or something?
0
 
RobSampsonCommented:
As far as I know, there's no native way, but a third party ActiveX component should help, such as this one:
http://www.example-code.com/vbscript/socket_connect.asp

Regards,

Rob.
0
 
Azhrei1Author Commented:
allright, I guess we're not going to get it working without a 3rd party component then, thanks for the help and the tips, the cache connection string could come in handy in the future :)
0
 
RobSampsonCommented:
Sure, no problem.  Thanks for the grade.  There are times when VBScript's built in capabilities just don't cut it, and unfortunately, third-party components can be pricy too.

Rob.
0

Featured Post

Choose an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program was designed in collaboration with national intelligence organizations and IT industry leaders.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now