This project is read-only.
1

Closed

Exception in System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)

description

i have a clickonce deployed WPF application where we have marked our SQL Local database as a data component. At times when the clickonce is upgraded our database is kind of inaccessible from the application and all DB operations fail.

Following log is seen in the log file:
Database Initialization Failed : Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
System.ArgumentException: Expansion of |DataDirectory| failed while processing the connection string. Ensure that |DataDirectory| is set to a valid fully-qualified path.
at System.Data.Entity.Core.Common.DbProviderServices.ExpandDataDirectory(String path)
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, Nullable
1 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)

When i went to the code piece(in bold above) I can see a if block like this:
      // Verify root folder path is a real path without unexpected "..\"
        if (rootFolderPath.Contains(".."))
        {
            throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
        }

When we watched the location of the data folder, it was something like this:
C:\Users\<USERNAME>\AppData\Local\Apps\2.0\Data\98O56D2Q.EM1\R4LXLEL4.85M\tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0\Data


So it results that our path at "tech..tion_0000000000000000_0003.0001_80c92a08f8b673c0" do contains (..).

But based on the if block check this actually does not satisfies the condition because it is not at the start of the folder location.

As per my suggestion the if block should be like:
        // Verify root folder path is a real path without unexpected "..\"
        if (rootFolderPath.StartsWith("..\", StringComparison.Ordinal))
        {
            throw new ArgumentException(Strings.ExpandingDataDirectoryFailed);
        }

Please suggest what should I do as the install folder path is not under control. The name and path is decided by the clickonce deployment strategy. Waiting for your reply.
Closed Mar 16 at 7:09 PM by ajcvickers
EF Team Triage: Thanks for reporting an issue on Entity Framework 6.x. This project is now maintained on GitHub (https://github.com/aspnet/EntityFramework6). Please file your issue on the GitHub issue tracker. We will no longer be monitoring this issue tracker for comments, so please do not reply here.

comments

ErikEJ wrote Mar 16 at 12:54 PM

Avoid using DataDirectory in your connection string, resolve the path yourself