Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi Professional
I want to backup from database in my project
my connection string is:

@"Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\myDatabase.mdf;
Initial Catalog=myDatabase;Integrated Security=True;User Instance=True";

but occurred error
Posted
Comments
Herman<T>.Instance 15-Aug-11 7:08am    
question 1: which error?
Simon Bang Terkildsen 15-Aug-11 7:08am    
What error did you encounter?

You're doing it wrong.

I know this answer seems vague, but it matches the quality of your question.

WHAT error are you getting - EXACTLY.
 
Share this answer
 
Comments
Simon Bang Terkildsen 15-Aug-11 7:27am    
"You're doing it wrong." you seem to say that quite alot today, mayby just but it in your signature, would safe time :) +5
#realJSOP 15-Aug-11 8:15am    
The quality of the question dictates the quality of the answer. Besides, our signatures don't show up in Q/A.
If you can connect to the database using this string in order to view records, then you should also be able to backup the database: Since you don't specify how you are doing that we can't debug that part for you, but there is an example here: http://www.geekpedia.com/tutorial180_Backup-and-restore-SQL-databases.html[^]
 
Share this answer
 
i am sure that this below link will help you a lot.
LINK
just read and follow instruction.

here is code spinet.

To BACKUP and RESTORE DataBase through SQLCMD.EXE :
PATH OF EXE:- C:\Program Files\Microsoft SQL Server\100\Tools\binn\SQLCMD.EXE
sqlcmd -S.\SQLExpress
1> BACKUP DATABASE dbName TO DISK = 'path'
2> GO
An alternative, single-line backup command:

sqlcmd -S.\SQLExpress -Q"BACKUP DATABASE dbName  TO DISK = 'path'"
(Note that you must enclose the path within quotes)

To Restore:

sqlcmd -S.\SQLExpress
1> RESTORE DATABASE dbName FROM DISK = 'path'
2> GO

For Restore with REPLACING EXISTING DATABASE
1> RESTORE DATABASE dbName FROM DISK = 'path'
2> WITH REPLACE
3> GO
 
Share this answer
 
v2
I wonder if you really mean backup using C# with the question, but if you do, then you:
- open the connection with working connection string
- create a SqlCommand object
- define a backup command in T-SQL
- execute the command using ExecuteNonQuery
- handle possible errors
- close the connection
- dispose the connection

And the backup command itself: BACKUP (Transact-SQL)[^]
 
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