Sign in to follow this  
Followers 0
K33p3r

Cannot connect to remote MSSQL server

9 posts in this topic

Good day everyone,

I am attempting to create a login mechanism by which you can access a remote MSSQL Server 2008 R2 database 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:

1) Used SQL Server Management Studio to allow remote connections as well as the proper permissions for the correct user to access the database.

2) Used SQL Server Configuration Manager to enable SQL Server Browser and the TCP/IP protocol with the proper configurations to access the server.

3) 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).

4) Added sqlservr.exe and sqlbrowser.exe to the firewall allowed programs list.

5) Installed MS SQL 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.

Is my code incorrect or do I have to make additional server/client configurations? Any help is appreciated.

Thank you for reading and have a great day,

K33p3r

Share this post


Link to post
Share on other sites



Did you use the same connection string for the local test (that was successful)?

I use an autoitscript to upload data to a SQL server and I only use the open method and feed it the connection string. I also just declare the server not serversql....

Not sure if that makes a difference.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Did you use the same connection string for the local test (that was successful)?

I use an autoitscript to upload data to a SQL server and I only use the open method and feed it the connection string. I also just declare the server not serversql....

Not sure if that makes a difference.

First of all, thank you for responding and secondly, I've used the same exact connection string for the local test and it worked without any problems whereas trying this code on the client to connect to the remote server failed showing the error previously mentioned.

Might you show me what exactly you had in mind?

Cheers,

K33p3r

Edited by K33p3r

Share this post


Link to post
Share on other sites

Bumping if anyone can help me with this issue. I apologize for any inconvenience.

Share this post


Link to post
Share on other sites

Find an answer? It's relevent for me.

Ed

Share this post


Link to post
Share on other sites

You said the server and client are on the same subnet right? You shouldn't have any issues then. The only thing I can think of is domain/workgroup issues. Can you browse a file share on the server without needing credentials? This is a basic way of testing permissions.

Share this post


Link to post
Share on other sites

1. Install Management Studio on the client machine.

2. Connect from Management Studio (on the client).

3. Fix whatever error you get.

4. Repeat 3 & 4 until the connection works.

5. Remove sqlexpress from your connection string.

6. Connect with your code.

7. Post results.

Share this post


Link to post
Share on other sites

1. Install Management Studio on the client machine.

2. Connect from Management Studio (on the client).

3. Fix whatever error you get.

4. Repeat 3 & 4 until the connection works.

5. Remove sqlexpress from your connection string.

6. Connect with your code.

7. Post results.

This is also a good solution to find the issue. Managment Studio should be able to connect from the client. Make sure sql server is set to mixed authentication mode so you can try connecting with the SA account or a local user account. The local user account must have read/write access to the database though.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

1. Install Management Studio on the client machine.

2. Connect from Management Studio (on the client).

3. Fix whatever error you get.

4. Repeat 3 & 4 until the connection works.

5. Remove sqlexpress from your connection string.

6. Connect with your code.

7. Post results.

This is also a good solution to find the issue. Managment Studio should be able to connect from the client. Make sure sql server is set to mixed authentication mode so you can try connecting with the SA account or a local user account. The local user account must have read/write access to the database though.

I appreciate all of your suggestions. I will post an answer as soon as I finish with other work I am currently having.

Strangely enough, I could connect and query the database without any problems using sqlcmd from the remote client. 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.

Cheers,

K33p3r

Edited by K33p3r

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