Jump to content

Need help with connecting to multiple MSSQL databases


Recommended Posts

Hi,

I'm writing a small app that shows a check box list of databases a user can access. The user will then check those boxes, and perform a fixed set of actions on the databases he/she selects.

After looking around here on how to use AutoIt with MSSQL, here is what I came up with:

$g_userName = InputBox("Login", "Please enter your username.", @UserName, "", 400, 50)
$g_password = InputBox("Login", "Please enter your password.", "", "*", 400, 50)
; Accesses database
$g_sqlConn = ObjCreate("ADODB.Connection")
$g_sqlRecordSet = ObjCreate("ADODB.Recordset")
$g_sqlConnStr = "Provider=SQLOLEDB;Data Source=" & $c_DATABASE_SERVER & ";Initial Catalog=DB1;User ID=" & $g_userName & ";Password=" & $g_password & ";"
$g_sqlConn.Open($g_sqlConnStr)

And I call Open() for each database. If it does not fail, I show the check box for that database. If I get an error, I know the user can't access that database.

Instead of relying on errors and exceptions, is there a better way to tell whether a user has access?

Many thanks!

Link to comment
Share on other sites

Instead of relying on errors and exceptions, is there a better way to tell whether a user has access?

Somthing like this:

$oDb.Open($DsnName)

If IsObj($oDb) = 0 Then

MsgBox(0,"","Not connected")

Exit

br, Reinhard

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...