0

I have a desktop application that works with SQL Server CE and EF using a code-first approach, I have large volume of users working with this.

The connection string that I am passing to DbContext class constructor,

@"Data Source=" + Path.Combine("Path to local app data", "Databasename.sdf") + ";Password=mypassword"

But on one of the Windows 7 SP1 (32 bit) machines, I am getting following error:

System.InvalidOperationException: Unable to complete operation. The supplied SqlConnection does not specify an initial catalog or AttachDBFileName.

at System.Data.Entity.SqlServer.SqlProviderServices.GetOrGenerateDatabaseNameAndGetFileNames(SqlConnection sqlConnection, String& databaseName, String& dataFileName, String& logFileName)
at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection) at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable1 commandTimeout, StoreItemCollection storeItemCollection)
at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.MigrateDatabaseToLatestVersion2.InitializeDatabase(TContext context) at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf1.b__e()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction1.PerformAction(TInput input) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action1 action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet1.Initialize() at System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery1.System.Linq.IQueryable.get_Provider() at System.Linq.Queryable.Any[TSource](IQueryable1 source)
at GCMApiSDK.DataService.d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at GCMApiSDK.AuthenticationDialog.<LoginButton_Click_1>d__11.MoveNext()

I am unable to figure out what is going wrong with that particular machine, because the same thing works for other Windows 7 users.

Plus I also tried re-installing SQL Server CE Runtime 3.5 SP2, but no luck.

To add more info, the database is successfully created in the specified location, but I'm unable to do other operations.

Aniket Bhansali
  • 630
  • 12
  • 33
  • 1
    Both Windows 7 and SQL Server CE 3.5 are **way beyond** end-of-life .... – marc_s Oct 26 '20 at 11:49
  • I agree, but client is using that, which unfortunately I don't have control over. Ultimately client is next to God. – Aniket Bhansali Oct 26 '20 at 11:50
  • @marc_s Is EF somehow trying to connect with SQL Server Express? I went through https://stackoverflow.com/questions/4116994/sql-server-express-connection-string-for-entity-framework-code-first so there it worked for SQL CE but failed for express. – Aniket Bhansali Oct 26 '20 at 12:06
  • Try adding `providerName="System.Data.SqlServerCe.3.5"` to your connection string to make it crystal clear what you're connecting to – marc_s Oct 26 '20 at 12:35
  • I installed pending "Windows updates" and it worked, For someone who stumbles here. – Aniket Bhansali Oct 26 '20 at 12:50
  • @marc_s I am back on Square 1, Still facing this issue on yet another machine, I had installed all pending updates too, and tried mentioning providerName also, but it doesn't seem to work. – Aniket Bhansali Dec 10 '20 at 08:19

0 Answers0