-2

I am using an SqlCe 4 database with an Entity Framework 6 code first data model.

I set the connection string in the DbContext constructor like so:

private static readonly string DATABASE_PASSWORD = "...";
private static readonly string CONNECTION_STRING = string.Format(@"Data Source={0};Password={1}", MyProject.Properties.Settings.Default.DatabaseLocation, DATABASE_PASSWORD);

public DataModel()
    : base(CONNECTION_STRING)
{
}

And when I run my application which uses this model it works.

In the designer in Visual Studio however it keeps freezing for about 30 seconds at a time when I try to view a WPF control that load a set of records in the View model constructor and I get an error message as follows:

Error   2   Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName.

I am not using SqlServer I am using Sql Server Compact so there should be no need to even think about using Sql Server.

Can anyone see anything wrong with my connection string?

Steven Wood
  • 2,675
  • 3
  • 26
  • 51
  • 3
    ([You know that compact is deprecated, right?](http://stackoverflow.com/questions/20363374/is-sql-server-compact-discontinued-from-visual-studio-2013/20364011#20364011)) – Aaron Bertrand Oct 02 '14 at 13:05
  • deprecated or not still better than Access – Steven Wood Oct 02 '14 at 13:05
  • 1
    When did I say that Access is even a viable alternative, never mind your only alternative? Did you click [the link](http://stackoverflow.com/questions/20363374/is-sql-server-compact-discontinued-from-visual-studio-2013/20364011#20364011)? You can use Express, LocalDB, SQLite, ... – Aaron Bertrand Oct 02 '14 at 13:07
  • That was my other option, I am using Sql Server CE, I asked a question about Sql Server CE, I do not have the option of changing Sql Server Ce and you response was not a helpful one. Its like saying I have a problem with my Car - well you should have bought.... – Steven Wood Oct 02 '14 at 13:09
  • 4
    This is why it was a ***COMMENT*** and not an ***ANSWER***. Since it seems like you are just starting out in this project because you haven't even made a single successful connection yet, and since a lot of people *don't know* that Compact is deprecated and shouldn't be used - especially in new development, I thought it might be helpful to bring it up. If you don't find it helpful, well, tough beans. The next reader might. Sorry for trying to help you but I'm going to leave my comments here because other readers might be a bit more appreciative. – Aaron Bertrand Oct 02 '14 at 13:10

1 Answers1

2

Viewing the error message ( ...The supplied SqlConnection.. ) I conclude that you are setting an SQlConection rather than SQlCeConnection

Make sure you set your SQL object like:

 conn = new SqlCeConnection(CONNECTION_STRING);
 conn.Open();
 SqlCeCommand cmd = conn.CreateCommand();
 cmd.CommandText = "..."

And make sure you have added a reference to the SQL Server Compact provider, System.Data.SqlServerCe.dll

apomene
  • 14,282
  • 9
  • 46
  • 72
  • +1 I presume this is the problem. Funny that the more important details of the code were left out of the original question. Also I wonder if the latest versions of Visual Studio even offer CE as an option anymore - perhaps why the OP has no reference to the provider. – Aaron Bertrand Oct 02 '14 at 13:26