I am trying to access database from a Class Library Project. I have connection string defined in App.config file like this
add name="EditRegionConnectionString" connectionString="Data Source=.\SQLExpress;Initial Catalog=testdb;Integrated Security=True"
providerName="System.Data.SqlClient"
I am trying to access this conenction string via code
Table<cont> table1 = new DataContext("EditRegionConnectionString").GetTable<cont>();
var t1 = from t in table1 select t;
//i am getting error here
t1.FirstOrDefault();
Error
A network-related or instance-specific
error occurred while establishing a
connection to SQL Server. The server
was not found or was not accessible.
Verify that the instance name is
correct and that SQL Server is
configured to allow remote
connections. (provider: Named Pipes
Provider, error: 40 – Could not open a
connection to SQL Server)
You need to actually use the connection string, and not just the name of it. Try something like: