0

I completed a C# project which has a .MDF database file created from Visual Studio Add new connection wizard and now have to deploy it on client's computer. I tried all the methods available on StackOverflow and on other sites but unable to deploy it. Can anybody please give a step by step easy process for this?

  • What was the issue with your attempts? Could you also clarify "all the methods available"? – tj-cappelletti Aug 07 '17 at 21:01
  • Is the MDF for a LocalDB or are you trying to load it into a full SQL Server instance? – JNYRanger Aug 07 '17 at 21:02
  • @virusstorm the problem is, the App is unable to access that mdf file. – Kamal Ashraf Gill Aug 07 '17 at 21:05
  • @JNYRanger honestly saying I am not sure if it is LocalDB or something else. I created it from Visual studio -> Server explorer -> Right click on data connection -> Add connection... -> Microsoft SQL Server database file and using Windows Authentication. – Kamal Ashraf Gill Aug 07 '17 at 21:08
  • @virusstorm here are all the methods from stackoverflow, [link](https://stackoverflow.com/questions/22712688/how-to-deploy-c-sharp-exe-with-mdf-file), [link](https://stackoverflow.com/questions/5795048/how-to-deploy-mdf-file), [link](https://stackoverflow.com/questions/40146336/how-to-deploy-c-sharp-windows-application-setup-file-with-database-and-how-to), [link](https://stackoverflow.com/questions/3210522/how-to-deploy-a-project-on-clients-computer) – Kamal Ashraf Gill Aug 07 '17 at 21:08

1 Answers1

0

It looks like you may need to install SQL Express, as an MDF is not usable without SQL Server running. During the install you can programatically attach the MDF. SQL Express is freely distributable.

https://www.microsoft.com/en-us/sql-server/sql-server-editions-express

https://www.microsoft.com/en-us/sql-server/developer-get-started/csharp/win/

Basically, you will want to install SQL Server (Express or full version), attach the DB your app uses, and modify your connection string in code (config file) to reference the instance of SQL Server you just installed. The server could be LOCALHOST.

DanielG
  • 1,669
  • 1
  • 12
  • 26
  • can you give me the connection string, if the .mdf file is placed in D drive? – Kamal Ashraf Gill Aug 07 '17 at 21:24
  • This may help: https://www.connectionstrings.com/sql-server/ You will still need to have SQL Server running on the machine. The "Server" portion of your connect string needs to resolve. After you install SQL Server Express on the target machine, you can use "LOCALHOST" OR something like .\SQLEXPRESS for your server value. – DanielG Aug 07 '17 at 21:26
  • there are a lot of connection strings there, which one to choose? – Kamal Ashraf Gill Aug 07 '17 at 21:29
  • Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=C:\MyFolder\MyData.mdf; – DanielG Aug 07 '17 at 21:31
  • https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-2016-express-localdb – DanielG Aug 07 '17 at 21:33