How would I create an EntityConnection string for an SqlServerCe database?
I tried following the MSDN Example on How to: Build an EntityConnection Connection String
const string PROVIDER = "System.Data.SqlClient";
static string BuildEntityConnString(string dbFileName, string password) {
// dbFileName is filename without the extension
SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder();
sqlBuilder.DataSource = PROVIDER;
sqlBuilder.InitialCatalog = dbFileName;
sqlBuilder.IntegratedSecurity = true;
sqlBuilder.Password = password;
string providerString = sqlBuilder.ToString();
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = PROVIDER;
entityBuilder.ProviderConnectionString = providerString
entityBuilder.Metadata = string.Format(@"res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", dbFileName);
string connString = entityBuilder.ToString();
using (EntityConnection con = new EntityConnection(connString)) {
con.Open();
Console.WriteLine("{0} Entity String created.", dbFileName);
con.Close();
}
return connString;
}
However, but it throws an 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)
With some searching on here, I was able to find info stating that the MSDN Example returns an SqlClient connection.
However, I was not able to find out how to return an Sql CE Connection.
I tried supplying the EntityConnection the SQL CE Connection String that allows me to open the .SWF database and read it conventionally:
const string PROVIDER = "Microsoft.SqlServerCe.Client.3.5";
static string BuildEntityConnString(string dbFileName, string password) {
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = PROVIDER;
entityBuilder.ProviderConnectionString = myCeConnectionString;
entityBuilder.Metadata = string.Format(@"res://*/{0}.csdl|res://*/{0}.ssdl|res://*/{0}.msl", dbFileName);
string connString = entityBuilder.ToString();
using (EntityConnection con = new EntityConnection(connString)) {
con.Open();
Console.WriteLine("{0} Entity String created.", dbFileName);
con.Close();
}
return connString;
}
This version throws a different error:
Unable to find the requested .Net Framework Data Provider. It may not be installed.
What could I be doing wrong?
I found this related SQL Server Fix, but the fix needs to be something I can set in my code so that my project will run on our Customers' computers at other locations without network administrators.