1

I am ready to finalize a winforms add in I have created for Excel which uses Add-In Express to publish.

This add in uses a sql server localdb database with mdf file.

My primary question is how to deploy the mdf file to target machines. So far, I have manually copied the mdf file to test machine, but when testing the add in it fails to connect to the file (localdb is installed).

Error message:

Exception Source: .Net SqlClient Data Provider Exception Type: System.Data.SqlClient.SqlException Exception Message: Cannot open database "MyDatabase" requested by the login. The login failed.

Is it even possible to just drop the mdf onto machine and everything work? If so, is there a guide somewhere that could help. Or do I have to generate the sql scripts to create the database locally? If I do have to generate the SQL scripts, is there a way to roll this up in the Click-Once deployment approach, or I do I need a seperate process?

wesmantooth
  • 625
  • 2
  • 11
  • 29
  • 1
    You can't use mdf without installed ms sql server. You can't just copy mdf, first You have to deattach from existing server and attach to new one (Your target computer, which must have installed mssql server - express version is free). Read this (from SO) : http://stackoverflow.com/a/10366632/3279496 – nelek Jul 26 '15 at 17:28
  • 1
    You should use `SqlCE` (.sdf file) instead `mdf`. In Sql Compact Edition you don't need to install sql or any thing except that special SqlCE.dll files. – Behzad Jul 26 '15 at 17:50
  • @nelek I do have localdb installed on the target machine and thank you for pointing out that other question. Any tips on reattaching with the mdf? – wesmantooth Jul 26 '15 at 18:43
  • @Behzad Khosravifar Yes I agree that CE is appealing for this project, but I have several views (which I could possibly convert to linq queries in the app) in the database and this reference says they are not supported. https://technet.microsoft.com/en-us/library/Bb896140(v=SQL.110).aspx – wesmantooth Jul 26 '15 at 18:43
  • 1
    all right, you can try **Sqlite** or **Firebird** or similar local databases instead **Sql server**. Because they provide portability without installation. just you need to convert your exist data to new database system. – Behzad Jul 26 '15 at 18:48
  • 1
    I think this might be a better reference: http://stackoverflow.com/questions/9655362/localdb-deployment-on-client-pc. – Brendan Green Jul 26 '15 at 23:25
  • 1
    CE is dead (no active development, in maintenance phase only fixing critical bugs). Sqlite and Firebird (and CE too) don't support various features and aren't supported as well by ORMs. And for all the people saying you can't just copy the mdf and attach with LoclDB, you obviously have no idea what LocalDB is. – kjbartel Sep 13 '16 at 11:12
  • @kbartel you are the only worthy upvote here. I can't believe the level of misinformation I see! Convert to Firebird are you kidding!!!! – Nick.Mc Jun 16 '17 at 04:31

1 Answers1

-1

This is how you deploy a WinForms application with LocalDB

  1. You have to create a localDB on your application and make sure the application will connect to that localDB.(if you don't know how to connect to local db, here => Connect to LocalDB. And make sure to create tables and procedures as same as your previous database.

  2. Follow this answer(ticked) with code(connection string)

  3. After this, you have to install Advanced Installer to create an installer for your application (the best choice I ever chose).

  4. Then Follow this to create an installer where you make sure to add a prerequisite of localDB (say localdb 2019) installer of your current version.

  5. This makes your application run on any pc and only requires localdb as a prerequisite to be installed which also comes with the installer.

  6. Make sure to leave a message not to delete localdb on the application installed location.

Opus Corpus
  • 115
  • 1
  • 8