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:
- Used SQL Server Management Studio to allow remote connections as well as the proper permissions for the correct user to access the database.
- Used SQL Server Configuration Manager to enable SQL Server Browser and the TCP/IP protocol with the proper configurations to access the server.
- Created a firewall Inbound and Outbound rule which allows access to TCP port 1433 and UDP port 1434 for the server and client (just in case).
- Added
sqlservr.exe
andsqlbrowser.exe
to the firewall allowed programs list. - Installed SQL Server Native Client 2008 R2 on the client PC.
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?