I am attempting to create a login mechanism by which you can access a remote SQL Server 2008 R2 database, in a private network, if the credentials are correct. I intend to implement the database at my work server and this program at a client which is in the same subnet as the server. Here is my code so far:
Func Login()
$loginGUI = GUICreate("Login", 250, 150, -1, -1) ; will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW)
GUICtrlCreateLabel ( "Input valid credentials to login", 40, 10,-1,-1)
GUICtrlCreateLabel ( "Username", 40, 40,-1,-1)
Local $userInput = GUICtrlCreateInput("", 100, 37, 100, 20)
GUICtrlSetState($userInput, $GUI_FOCUS)
GUICtrlCreateLabel ( "Password", 40, 70,-1,-1)
Local $passwordInput = GUICtrlCreateInput("", 100, 67, 100, 20, $ES_PASSWORD)
Local $loginButton = GUICtrlCreateButton("Login", 40, 105, 70)
Local $exitButton = GUICtrlCreateButton("Exit", 130, 105, 70)
GUISetState()
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg(1)
Switch $msg[0]
Case $loginButton
$user = GUICtrlRead($userInput)
$password = GUICtrlRead($passwordInput)
Global $loginCon = ObjCreate( "ADODB.Connection" )
With $loginCon
.ConnectionString =("DRIVER={SQL Server};SERVER=192.168.1.30\SQLEXPRESS;DATABASE=Test;UID="&$user&";PWD="&$password&";")
.Open
EndWith
If ($user ="" and $password="") or @error Then
MsgBox(48, "Login error", "Connection failed! Wrong Username/Password.")
GUICtrlSetData($userInput, "")
GUICtrlSetData($passwordInput, "")
GUICtrlSetState($userInput, $GUI_FOCUS)
Else
$loginCon.Close
GUIDelete()
Main()
ExitLoop
EndIf
Case $exitButton
GUIDelete()
ExitLoop
Case $GUI_EVENT_CLOSE
GUIDelete()
ExitLoop
EndSwitch
WEnd
EndFunc
I've also did the following actions:
sqlservr.exe
and sqlbrowser.exe
to the firewall allowed programs list.I could connect locally to my database using the server IP but I get the following error when attempting to connect from the remote client to the server:
err.description is: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
Strangely enough, I could connect from the remote client using sqlcmd
. I also have to mention that I am currently using my laptop to hold my test database. It's IP is assigned by the DCHP server from work and always remains the same.
Is my code incorrect or do I have to make additional server/client configurations?
Instead of doing that way I suggest to have client and server written in autoit. Put server to remote computer and make it interact with database locally. Than return what you want to client. This approach is more secure also. Here is where you can start