none
WinForms and EntityFramework RRS feed

  • Question

  • Hi,

    I have an application that currently opens up a 3rd party DataSource that pulls the data, does some ETL, well the T mostly. The application then stores the data in a local database (LocalDB), I store it here since our network connections in Africa can be quite slow or non-existent.

    Once I have the data on my LocalDB I call a WebAPI on an MVC project that then saves all the data on that database hosted in the cloud. For portability, I am busy getting it to run from a thumb drive. I want the data to save to it, but it keeps saving to the user's Documents folder.

    When I have no connection string in my App.config EF generates the database perfectly, deletes it when needs to. Once I put the connection string in my App.config it keeps breaking with "error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name in invalid."

    Case 1:

      <connectionStrings>
        <add name="LocalDBContext" connectionString="
             Data Source=(localdb)\\mssqllocaldb;
             Initial Catalog=PSIologist.LocalDBContext;
             Integrated Security=True;MultipleActiveResultSets=True"
             
             providerName="System.Data.SqlClient" />
      </connectionStrings>
      

    Error 50.

    Case 2:

      <connectionStrings>
        <add name="LocalDBContext" connectionString="
             AttachDbFilename=|DataDirectory|\PSI-Data.mdf;
             Data Source=(localdb)\\mssqllocaldb;
             Initial Catalog=PSIologist.LocalDBContext;
             Integrated Security=True;MultipleActiveResultSets=True"
             
             providerName="System.Data.SqlClient" />
      </connectionStrings>

    Error 50.

    This happens after the following code gets executed

                using (LocalDBContext db = new LocalDBContext())
                {
                    if (db.Database.Exists()) 
                        db.Database.Delete();
                    
                    try
                    {                
                        db.Database.CreateIfNotExists();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
    
                    if (db.Database.Exists()) MessageBox.Show("DB reset complete"); // employees "+count);
                    else MessageBox.Show("DB reset failed");          
                }  

    .

    Any idea what I am missing on something this simple?

    • Moved by CoolDadTx Tuesday, April 4, 2017 1:58 PM EF related
    Tuesday, April 4, 2017 12:33 PM

All replies

  • Your server name is not correct for LocalDB, if that is what you're trying to use. LocalDB uses (localdb)\v{version} syntax for connecting. Refer to the subsections around LocalDB here to get the correct connection string for the variant you're trying to use.

    Note that the DB is actually published under several names when the database is also a project in your solution. It appears you might be trying to use the project name instead of the LocalDB instance name.

    Michael Taylor
    http://www.michaeltaylorp3.net

    Tuesday, April 4, 2017 1:58 PM
  • Hi Heinz09,

    >>with "error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name in invalid."

    As CoolDadTx said, please check the version of localdb. On SQL Server 2012, we used "(localdb)\v11.0" as instance  name. The name of the automatic LocalDB  instance is no longer related to SQL Server version number (v11.0 = SQL Server  2012, v12.0 = SQL Server 2014). Thus, we should use "(localdb)\mssqllocaldb" as  server name to connect to LocalDB automatic instance on SQL Server 2014.

    For more information, please refer to:

    http://www.sqlcoffee.com/SQLServer2014_0010.htm

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 7, 2017 6:21 AM
    Moderator
  • Ah okay, the thing is I am trying to move the location of the files to removable media since we do not have network access everywhere I want to do the ETL on a piece of removable to upload with a more stable/existant network connection.

    Do you maybe have any alternative?

    Monday, April 10, 2017 6:15 AM
  • Hi Heinz09,

    Please check the following thread, which provide a solution and check if it works for you.

    1.Make sure you have .NET Framework 4.0.2+ installed

    2.Set up your AppPool to run under the NetworkService account.

    3.Create a login for that account in your db.

    4.Share your instance with all users by running  SqlLocalDB share Kentico KenticoShared

    5.Use connection string in the following format:

    http://stackoverflow.com/questions/26769464/sql-network-interfaces-error-50-local-database-runtime-error-occurred-the-s

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, April 20, 2017 6:58 AM
    Moderator