Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:31:37+00:00 2026-06-12T14:31:37+00:00

I have a unit test project in Visual Studio 2012 where I am storing

  • 0

I have a unit test project in Visual Studio 2012 where I am storing the AdventureWorks MDF file for SQL Server 2012 (the file is named AdventureWorks2012_Data.mdf). In the Visual Studio Server Explorer, I am able to add the MDF in the Data Connections and browse the database. Right clicking on $/Data Connections/AsventureWorks2012_Data.mdf and selecting properties gives me access to the connection string as follows:

Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Projects\Common\Source\Framework\Framework.Data.Tests\AdventureWorks2012_Data.mdf;Integrated Security=True;Connect Timeout=30

I copied this into my Entity Framework connection string in the app.config file as follows:

<!-- Works :-) -->
<connectionStrings>
  <add name="AdventureWorksEntities" 
       connectionString="metadata=res://*/Repository2Tests.AdventureWorks.csdl|res://*/Repository2Tests.AdventureWorks.ssdl|res://*/Repository2Tests.AdventureWorks.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Projects\Common\Source\Framework\Framework.Data.Tests\AdventureWorks2012_Data.mdf;Integrated Security=True;Connect Timeout=30App=EntityFramework&quot;" 
       providerName="System.Data.EntityClient" />
</connectionStrings>

Note that the AttachDbFilename contains the full path of the MDF file as:
C:\Projects\Common\Source\Framework\Framework.Data.Tests\AdventureWorks2012_Data.mdf

When I run the unit tests, everything is fine as expected.

I changed AttachDbFilename to |DataDirectory|\AdventureWorks2012_Data.mdf as described in “ADO.NET Entity Framework Connection Strings” and I set the DataDirectory as described in “ADO.NET |DataDirectory| where is this documented?” so that my connection string now is as follows:

<!-- Doesn't work :-( -->
<connectionStrings>
  <add name="AdventureWorksEntities" 
       connectionString="metadata=res://*/Repository2Tests.AdventureWorks.csdl|res://*/Repository2Tests.AdventureWorks.ssdl|res://*/Repository2Tests.AdventureWorks.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AdventureWorks2012_Data.mdf;Integrated Security=True;Connect Timeout=30;App=EntityFramework&quot;" 
       providerName="System.Data.EntityClient" />
</connectionStrings>

The change to using |DataDirectory| resulted in the following runtime error:

System.Data.EntityException: The underlying provider failed on ConnectionString. ---> System.ArgumentException: URI formats are not supported.
HResult: -2147024809
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)
at System.IO.Path.GetFullPath(String path)
at System.Data.Common.ADP.GetFullPath(String filename)
at System.Data.Common.DbConnectionOptions.ExpandDataDirectory(String keyword, String value, String& datadir)
at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)
at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
--- End of inner exception stack trace ---
HResult: -2146233087
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, ConnectionStringSettingsCollection connectionStrings)
at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.Create()

I have researched this for a couple days now and tried countless variations without success. I even debugged into Microsoft code but with compiler optimizations I am unable to see any debugging information on the stack.

Has anyone run across this specific problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:31:38+00:00Added an answer on June 12, 2026 at 2:31 pm

    I finally solved the problem when I set out to submit a bug report to Microsoft and worked on reproduction steps.

    To make a long story short, the problem was in the code that set the DataDirectory:

    AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory);
    

    The issue was that my dataDirectory variable was getting initialized as file://C:/myfolder/etc/ instead of C:\myfolder\etc\. I corrected the code responsible for that and the problem is resolved. Incidentally, the code I used is:

    // in the test assembly initializer
    String dataDirectory = AppDomain.CurrentDomain.GetApplicationPath();
    AppDomain.CurrentDomain.SetData("DataDirectory", dataDirectory);
    
    // GetApplicationPath calls into the following extension method
    /// <summary>
    /// Defines a set of extension methods on <see cref="AppDomain"/> objects.
    /// </summary>
    public static class AppDomainExtensions
    {
        /// <summary>
        /// Gets the application path (works for both ASP.NET and unit tests).
        /// </summary>
        /// <returns></returns>
        public static string GetApplicationPath(this AppDomain appDomain)
        {
            string binPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            return binPath.Substring(0, binPath.LastIndexOf("bin", StringComparison.InvariantCultureIgnoreCase));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unit test project in Visual Studio 2010 (.NET 4) that utilizes
I have a Visual Studio solution named - UnitTestProject, unit test with xunit framework.
I have a Visual Studio 2010 project with Unit Test project. We have 5
I have some unit-tests within a Visual Studio project with the attributes: [TestMethod] [ExpectedException(typeof(..Exception))]
I have made a project in visual studio and also implemented unit testing. The
I have installed the new Visual Studio 2012 Ultimate. I have created a Test
Visual studio created a unit test project for me based on a method (right-click
I've got a CSV file that I added to a Visual Studio Unit Test
I have a bunch of unit tests in my visual studio project and code
I have a Test Project in Visual Studio I'd like to use to test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.