0

I have built an app with winforms application and added a local database to my project using based-data source.

on the app load event the app connects to the database and loads its components accordingly.

everything works fine on my pc but the problem is when I am transferring the app to other computers. I am getting an error every time the app tries to connect to the database (local Database Run time error occurred).

Tried to install SQL Express localdb 12 on the other computers and checked that the service: SQL Server VSS Writer is running but still getting the same error. Note: the database.mdf file exists in the same location on all the computers.

SQL Error:

enter image description here

How can I fix it?

Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
Asad Blum
  • 126
  • 1
  • 6
  • Connection string: string cn_conn = "Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Gear\\DataBase\\Dashboard_Database.mdf; Integrated Security = True; Connect Timeout = 60; ConnectRetryCount = 10" – Asad Blum Feb 28 '19 at 12:44
  • Check SQL is actually running and the event logs on those machines for errors – BugFinder Feb 28 '19 at 12:45
  • See if this answer helps: https://stackoverflow.com/a/9691562/1220550 – Peter B Feb 28 '19 at 12:46
  • thanks everyone for your help , the issue is resolved after upgrading sqllocaldb from v11.0 to v12.0 – Asad Blum Feb 28 '19 at 15:58

1 Answers1

0

I suggest not to hard-code connection string in code. Move connection string in configuration file and access from their and rebuild your application. Now when you move your project to other computer, you move configuration file which is generated by build as well. On new computer, open DB and freshly copy your connection string and replace it in your configuration file and then run your application. Hope this will help.

Ashif Nataliya
  • 912
  • 2
  • 13
  • 28