0

I am trying to make a simple database application. It is just writing and reading from local database file using c# winform, but when i move the application folder to another pc, it comes with error. I thought it is just some dumb mistake with connstring or file accesses but when i click continue and the Application starts, there is even nothing loaded in combo boxes (which should be filled normally, without using any database stuff). Sorry for my English and thanks for response.

I cannot post image because i am new here but the exception says among other text this:

error 50 - local database runtime error occurred. The specified LocalDB instance does not exist.

5
  • 3
    LocalDB is a feature of SQL Server Express. You can't use it unless SQL Server Express is installed Commented Feb 19, 2019 at 12:20
  • 3
    well unless you copied the database along with the application, and also installed LocalDB/SQL Express services on the new PC then naturally it will not exist. It doesn't get there by magic! softwareengineering.stackexchange.com/questions/92948/… might be useful background. P.S. Of course if the different copies of your application all need to have access to, and share, the same data then you need a central DB server rather than separate copies on each PC. Depends on your requirements. Commented Feb 19, 2019 at 12:20
  • Your app is failing to connect to database, and you probably aren't handling correctly the exception so it can continue to work offline. Commented Feb 19, 2019 at 12:20
  • 1
    If you want a simple embedded database that doesn't require any installations try SQLite. SQL Server is far more powerful but it does require an installation Commented Feb 19, 2019 at 12:20
  • P.S. "I cannot post image because i am new here" ...that's fine. We'd rather have your error message as text, because it is actually a piece of text, not a picture. When it's text, it's copyable, searchable and usually a lot easier to read than when shown within a compressed jpg. Sames goes for code snippets or database data. If it's text, paste it as text. Commented Feb 19, 2019 at 13:06

2 Answers 2

2

The solution really depends on what is your application's design.

Centralized Database:

If your application is supposed to use the centralized database - meaning multiple c# winform applications connect with same database.

Then you will have to make sure that the database server's IP address / machine name / Identifier is mentioned as "Data Source" in the connection string.

For ex. below connection string shows, how you will connect to database if windows authentication is to be used for connection. You will have to replace Data Source as your IP address and Initial Catalog with the database name

Data Source=your-server-address;Initial Catalog=your-database;Integrated Security=TRUE;

Local Database:

If your application is supposed to use local database i.e. for every c# winforms application user, there will be local database on his machine, Then you will have to make sure that the required components (i.e. SQL Express, SQL or any other database server you want to use) are installed.

Hope this clarifies.

Sign up to request clarification or add additional context in comments.

Comments

1

Check your LocalDB connection string and point it to the right file location as you can see below (taken from here). Its path is now different as you moved your application (AttachDBFilename attribute)

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source= 
     (LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-MvcMovie-fefdc1f0-bd81-4ce9-b712- 
      93a062e01031;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet- 
     MvcMovie-fefdc1f0-bd81-4ce9-b712-93a062e01031.mdf" 
     providerName="System.Data.SqlClient" /> 
</connectionStrings>

1 Comment

This assumes that SQL Express is actually installed on the second PC. But we have no evidence for that. OP just said they "copied the application folder" of their .NET application. Unless SQL Express is already installed then your solution alone will not resolve the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.