Link to home
Start Free TrialLog in
Avatar of Azhrei1
Azhrei1Flag for Netherlands

asked on

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.
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, perhaps you could find a similar connection string for your database from here:
http://connectionstrings.com/

Regards,

Rob.
Avatar of Azhrei1

ASKER

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.
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

Avatar of Azhrei1

ASKER

crosspost? :)
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.
Avatar of Azhrei1

ASKER

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 :)
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.
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Azhrei1

ASKER

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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Azhrei1

ASKER

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 :)
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.