Keyword not supported in Connection String: 'database'
You are using SqlCeConnection
not a SqlConnection
This class (SqlCeConnection) is for Sql Compact Edition
where the syntax rules of the connection string are different. For example:
Data Source=MyData.sdf;Persist Security Info=False;
Instead your connection string is for a Sql Server
or Sql Server Express
.
So, if your target database is a SqlServer db as your tag indicates then you need to use
using (var cn = new SqlConnection(connectionString))
using (var cmd = new SqlCommand(selectSql, cn))
{
....
}
adam
I am a Software Engineer with 11 years of professional experience. I work with ASP.NET, C# & VB.NET, JS/JQuery and SQL on a daily basis. I am on stackoverflow to grow and learn as a professional developer give back to the community in my free time
Updated on July 09, 2022Comments
-
adam almost 2 years
Very new to C# and VS2012.
I'm trying to connect to a local database connection.
Here is the code
string selectSql = "select * from Tasks"; string connectionString = "Data Source=adamssqlserver;database=master;Integrated Security=true;"; using (var cn = new SqlCeConnection(connectionString)) using (var cmd = new SqlCeCommand(selectSql, cn)) { cn.Open(); using (var reader = cmd.ExecuteReader()) { //do something } }
Here is the error
Keyword not supported: 'database'.
If I put in Initial Catalog first
"Data Source=adamssqlserver;Initial Catalog=etc;"
Then the error gives the same message but for "Initial Catalog".
Here is my data connection