Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close concatenated odbc string connection with variable

Status
Not open for further replies.

dbcoh316

Technical User
Mar 31, 2022
1
US
Hello!

I am unable to figure out how to close the end of my DB string connection, in conjunction with a variable to change the database name.


'Code start
If DATABASE = "EDGEDEV" THEN
var_server = "VISUALERP\DEV"
ELSE
var_server = "VISUALERP"
END IF


SET objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=SQLOLEDB;User ID=USERNAME;Password=PASSWORD!;DATABASE="&DATABASE&";SERVER=" & var_server & "

'Code End

The trouble is at the end after the SERVER = my variable then it needs to be closed with a quotation mark but i'm getting some vbscript error about some unterminated string constant.

How do I close my connection?

Thank you in advance!

-David
 
try this:
Code:
DATABASE = "EDGEDEV"

If DATABASE = "EDGEDEV" THEN
var_server = "VISUALERP\DEV"
ELSE
var_server = "VISUALERP"
END IF

conn_str = "Provider=SQLOLEDB;User ID=USERNAME;Password=PASSWORD!;DATABASE="&DATABASE&";SERVER=""" & var_server & """"

wscript.echo conn_str

'SET objConnection = CreateObject("ADODB.Connection")
'objConnection.Open conn_str

Output:
Code:
Provider=SQLOLEDB;User ID=USERNAME;Password=PASSWORD!;DATABASE=EDGEDEV;SERVER="VISUALERP\DEV"
 
If it doesn't connect, try adding \\ in front of the server name.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top