Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends,
I used my database as mdf file in my application as following connection string

_sqlCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HealthFMRdb.mdf;Integrated Security=True;User Instance=True");


I used sql server 2008 r2 express And now I want to writ the code for Restore the backup of my database on this file at the same Directory, please help me how to do that,
thanks in advance

What I have tried:

I didn't find such code that fulfil my need
Posted
Updated 2-Jul-18 21:48pm
Comments
[no name] 3-Jul-18 11:12am    
Don't you have SQL Server Management Studio?

If you "attach" in SSMS, then you will be able to backup and restore using the "Tasks" menu.

"Restore" is usually something done "intentionally"; and not under program control (as are backups).

1 solution

That's not a DB that needs a restore - you are attaching it, which is a special "developer mode" of SQL Express (that isn't available in the full version) which temporarily hands the file to SQL server, and spins up a separate instance of SQL to handle it. When the connection is closed, the file is released by SQL.

So backup and restore of that file is a file system function, nothing to do with SQL. Look at how you backed the file up, and it should be fairly obvious how you restore it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900