Reputation:
I want to create a empty local database inside my project's folder and I've error:
An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
on the line
conn.Open();
I'm lost with what I need to do. Any idea what is causing this? I tried a few solutions - this one of them...
SqlCeConnection conn = null;
try
{
conn = new SqlCeConnection("Data Source = bd-avalia.sdf; Password ='<asdasd>'");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "create table cliente(id_cliente int identity not null primary key, nome varchar not null, password not null int)";
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
the error:
Upvotes: 0
Views: 1628
Reputation: 411
Change the cmd.CommandText as follows:
"CREATE TABLE dbo.[cliente] ([id_cliente] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY, nome [varchar] NOT NULL, password [int] NOT NULL)";
Upvotes: 0
Reputation: 411
Change the cmd.CommandText
as follows:
SqlCeConnection conn = null;
try
{
conn = new SqlCeConnection("Data Source = bd-avalia.sdf; Password ='<asdasd>'");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLE dbo.[cliente] ([id_cliente] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
nome [varchar] NOT NULL, password [int] NOT NULL)";
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
Upvotes: 0
Reputation: 23113
If you debug into the code (or output it somehow) you can check the NativeError
property of the SqlCeException
, which should tell you the cause of the exception.
See http://technet.microsoft.com/en-us/library/aa237948(v=sql.80).aspx for the explanation of the code.
Upvotes: 1