0

This is my first time with SQL Server 2014. I normally use Access database. My question is how can I move the .mdf file (database file) to my application path to use it on different machines?

I'm using this connection string in the app.config :

<connectionStrings>
    <add name="Conn"
         connectionString="Server = DESKTOP-TP1616Q; Database=Exchange_DB; user Id=sa;Password=Password1;"/>
</connectionStrings>

How can I change it to read from a .mdf file in the application folder(Debug) ?

My Question is how to change the connection string to make the application read from the moved mdf in the Debug folder, thank you.

Rabeea qabaha
  • 526
  • 8
  • 23

1 Answers1

1

You can use this code to choose backup and move .mdf and .ldf file to which folder that you want.

RESTORE DATABASE DatabaseName FROM DISK='+QuotedStr(OpenDialog1.FileName)+' WITH MOVE ''Test'' TO '''+ExtractFilePath(Application.ExeName)+'copytest.mdf'' '+',MOVE ''Test_log'' TO '''+ExtractFilePath(Application.ExeName)+'copytest.ldf''
  • I already moved the mdf and the ldf to the application file (Debug) but what im asking for , how to change the connection string to make the application read from the moved mdf , thank you – Rabeea qabaha Aug 28 '16 at 10:25
  • @Rabeeaqabaha,by that code you create database in sqlserver and then you should set address of connection string – saharghodsbin Aug 28 '16 at 13:31