Sign in to follow this  
Followers 0
DBowers

Checks to see if username/password is correct for database login

3 posts in this topic

Hi,

I am using the following code block to log into a database from AutoScript:

$userName = InputBox("Login prompt", "Please enter your username.", "", "", 400, 50)
$password = InputBox("Login prompt", "Please enter your password.", "", "*", 400, 50)

$v_sqlConn = ObjCreate("ADODB.Connection")
$v_sqlRecordSet = ObjCreate("ADODB.Recordset")
$v_sqlConnStr = "Provider=SQLOLEDB;Data Source=myDSr;Initial Catalog=default;User ID=DBowers;Password=BowersD;"
$v_sqlConn.Open($v_sqlConnStr)

$v_sqlQuery = "SELECT * FROM TBL"
$v_sqlRecordSet.Open($v_sqlQuery, $v_sqlConn)

How would I know whether the username/password is right, and prompt for username/passwords again until they work?

Thanks!

Share this post


Link to post
Share on other sites



If the logon is incorrect, do you get a error on the return?

Hi,

Thanks for the quick reply. On invalid login, I got the following error:

Line 130 (File "C:\test.au3"):

$v_sqlConn.Open($v_sqlConnStr)
$v_sqlConn.Open($v_sqlConnStr)^ERROR

Error: The requested action with this object has failed.

I have tried using the following block to catch the error right after $v_sqlConn.Open() but that didn't work.

If @error Then
        MsgBox(0x40000, 'Object', 'Failed')
    EndIf

Any suggestions? Thanks!

Share this post


Link to post
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
Sign in to follow this  
Followers 0