0

I have two computer on my local wireless modem network.

BEHZAD-PC---->install sql server on it.
AKBAR-PC----->want to access BEHZAD-PC sql server data with c#.

and my connection string on akbar-pc is:

string conn = "Data Source=BEHZAD-PC;Initial Catalog=brilliantit.ir_behitable;Integrated Security=True";

How can I do this?

Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
elnaz irani
  • 277
  • 1
  • 3
  • 11
  • 2
    possible duplicate of [How to connect to sql server database via LAN](http://stackoverflow.com/questions/19146281/how-to-connect-to-sql-server-database-via-lan) – Tinwor May 18 '15 at 15:15
  • 1
    Are both of the PCs in the same windows domain? – paul May 18 '15 at 15:15
  • No,i have a wireless modem,and two pc connect together with this modem – elnaz irani May 18 '15 at 15:19
  • I don't see any issue with your current connection string. try and see if you can ping both the machine from each other? If yes, then you shouldn't be facing any issue connecting then with your existing con string. – Rahul May 18 '15 at 15:42

3 Answers3

1

Steps to connect to SQL Server on another machine:

  1. Configure SQL Server for remote access. Here you can find how to enable TCP/IP connection to SQL Server

  2. If you don't use the default port number for TCP/IP protocol with your SQL Server, you may want to see how to pass the port number: here (BUT generally I don't think it applies to your case)

  3. Be sure whether your SQL Server instance is configured for mixed mode authentication: here

  4. Make a proper login from Security->Login. For simplicity do not check "Enforce password policy", "Enforce password expiration" and "User must change password at next login" . Then in the User Mapping tab get the read/write access for this login to the target database.

Community
  • 1
  • 1
Hossein Narimani Rad
  • 31,361
  • 18
  • 86
  • 116
  • i test your solution and i get this error:Login failed for user 'behzad' – elnaz irani May 18 '15 at 15:46
  • my connection string is:string conn = "Data Source=BEHZAD-PC;Initial Catalog=brilliantit.ir_behitable;Persist Security Info=True;User ID=behzad;Password=beh1368421;Connect Timeout=300000"; – elnaz irani May 18 '15 at 15:46
  • You should have such login (user=behzad, pass=...) defined in that SQL Server instance which you are going to connect. Moreover you should get the access to the initial catalog for this user. – Hossein Narimani Rad May 18 '15 at 15:49
  • i create user=behzad and pass=beh1368421 but i get this message:can not login user 'behzad' – elnaz irani May 18 '15 at 16:07
  • i create with step by step with your solution but i get this error:TITLE: Connect to Server ------------------------------ Cannot connect to BEHZAD-PC. ------------------------------ ADDITIONAL INFORMATION: Login failed for user 'RARA'. (Microsoft SQL Server, Error: 18456) For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&EvtSrc=MSSQLServer&EvtID=18456&LinkId=20476 ------------------------------ BUTTONS: OK ------------------------------ – elnaz irani May 18 '15 at 17:07
  • These are steps: 1. Enable remote connection to sql server 2. Prepare a proper login with read/write access to the target database 3. Make a LAN and connect to the SQL Server using (IP,port) and login informations – Hossein Narimani Rad May 18 '15 at 17:13
  • Following Error:18456, there may be another issue. Ensure whether you have enabled Mixed mode authentication on your SQL Server: Right click on the Server->Properties->Security->Check `SQL Server and Windows Authentication mode` – Hossein Narimani Rad May 18 '15 at 17:18
  • excuse me i am beginner in sql server!,how can i enable remote connection ?database read/write?make lan connect? how can i enable mixed mode? – elnaz irani May 18 '15 at 17:36
  • thanks for pay attention my problem,when i create a user,and i want to connect my database with this account,in Connect to server windows,whats is ServerName field?is this my pc name?BEHZAD-PC? – elnaz irani May 18 '15 at 18:23
  • when i enter password in login user define level,i define 1368421 but when i return back i see change the password! – elnaz irani May 18 '15 at 18:26
  • The server name is the IP address. You see the change the password because you didn't follow the step 4 exactly (You leaved the "User must change password at next login" as checked when defining the login). BUT No problem. simply change the password and use that changed password in connection string – Hossein Narimani Rad May 18 '15 at 18:32
0

It depends if you have SQL Server Express or not. I suppose you have express version because you are asking this. In this case you have to enable some protocols and start SQL Server Browser service.

look here https://technet.microsoft.com/en-us/library/ms165647(v=sql.90).aspx

ferdinand
  • 970
  • 1
  • 7
  • 14
0
Data Source=IP of your server;Initial Catalog=yourDB;Persist Security Info=True;User ID=yourUser;Password=yourPassword;Connect Timeout=just a timeout connection

Remember a couple of things:

Community
  • 1
  • 1
Orlando Herrera
  • 3,481
  • 1
  • 34
  • 44