views:

126

answers:

2

Hi,

I am supplying a batch script to create a DSN connection in the user computer before they start to use my application. I am using this in a .bat file.

ODBCConf ConfigSysDSN "SQL Server" "DSN=CONNAME|SERVER=PCNAME\INSTANCENAME

But I want to make sure they will be able to connect to the database, considering the fact that proper drivers may not be installed in their systems. So, is there any way to check the connection from the same batch file and inform the user if something unable to connect to the database?

thanks.

A: 

You can use OSQL.EXE to make a connection to the database.

Preet Sangha
osql comes with mssql server or the driver?
JPro
It's a client side tool. So when you install the cliet libraries, I'm sure it will be there.
Preet Sangha
+1  A: 

You can use a script;

cscript test.js //nologo
if errorlevel == 1 @echo "FAILED"

where test.js is

var exitcode = 0;
try {
    var C = new ActiveXObject("ADODB.Connection");
    C.Open("DSN=THEDSN;Uid=???;Pwd=???");
    WScript.Echo("Connected!")
} catch (e) {
    WScript.Echo("Failed to connect: " + (e.message || "No details"))
    exitcode = 1;
} finally {
    (C.State == 1) && C.Close();
    C = null;
    WScript.Quit(exitcode);
}
Alex K.