In my post here , I write about connecting to MS-SQL Server. One of my reader/googler ask me about how to handle if let say the password or username are wrong.
Here is the way how to handle it. I think there are another way to do it but personally I find that, this is the easiest way to do it.
#include <ie.au3>
_IEErrorHandlerRegister()
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=MySvr;DATABASE=MyDB;UID=MyUser;PWD=MyPwd;"
$conn.Open($DSN)
if @Error Then
MsgBox(0,"Error",$IEComErrorDescription)
Else
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.Open( "SELECT @@VERSION AS myVersion", $conn )
MsgBox(0, "AutoIT-SQL Result", "Value = " & $rs.Fields( "myVersion" ).Value )
EndIf
if IsObj($conn) Then $conn.close
I always believe that I can do almost everything using AutoIt. Well, since I need to do a lot of import and export job manually, I just wondering why not I just automagically do it using AutoIt.