K33p3r Posted September 21, 2012 Share Posted September 21, 2012 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: expandcollapse popupFunc 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 Link to comment Share on other sites More sharing options...
spudw2k Posted September 21, 2012 Share Posted September 21, 2012 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. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
K33p3r Posted September 21, 2012 Author Share Posted September 21, 2012 (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 September 22, 2012 by K33p3r Link to comment Share on other sites More sharing options...
K33p3r Posted September 22, 2012 Author Share Posted September 22, 2012 Bumping if anyone can help me with this issue. I apologize for any inconvenience. Link to comment Share on other sites More sharing options...
EdWilson Posted October 16, 2012 Share Posted October 16, 2012 Find an answer? It's relevent for me. Ed Link to comment Share on other sites More sharing options...
kudrow Posted October 17, 2012 Share Posted October 17, 2012 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. Link to comment Share on other sites More sharing options...
agreiner Posted October 17, 2012 Share Posted October 17, 2012 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. Link to comment Share on other sites More sharing options...
kudrow Posted October 17, 2012 Share Posted October 17, 2012 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. Link to comment Share on other sites More sharing options...
K33p3r Posted October 18, 2012 Author Share Posted October 18, 2012 (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 October 18, 2012 by K33p3r Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now