Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Suppose you have installed SQL Server Express 2008 R2 on a PC and you want to write a program(in C#) able to connect(make queries) to a database hosted by the mentioned database engine, but the program will be running on another machine; all machines are in the same network(even the same workgroup - Assume a network in your home)

You want to use Entity Data Model Framework to make your life easier.

How can you solve the problem? How do you make the program able to recognize the SQL Server on another machine? How do you connect to the database?
Posted

1 solution

Hi,
just add to web.config connectionstring section with connection string and and set data source to valid name of instance

XML
<connectionStrings>
   <add
      name="LocalSqlServer"
      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
      providerName="System.Data.SqlClient"
   />
</connectionStrings>


http://msdn.microsoft.com/en-us/library/bf7sd233.asp[^]

but don't forget to set all connection string properties of all object working with database.

Regards
Robert
 
Share this answer
 
Comments
arpoarpo 14-Nov-10 9:26am    
Thank you Robert, I was confused 'cause the machines were over a network and the connection string can't use a Trusted_Connection. I was doing test in the same PC where the SQL Server is intalled and everything were fine because you can use Windows Authentication to connect to database but when I was running the program on another PC with that Connection String I was receiving ERRORS.

Thank you so much for your answer,

Best Regards, Angel
Kanasz Robert 14-Nov-10 12:04pm    
Hi,
can you set SQL Authentication mode on SQL Server to mixed mode? That could help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900