I want to backup and restore the database by using vb.net.I have a problem here.
.This dialogue box appear.


[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open backup device 'C:\Documents and Settings\S\My Documents\sales.Bak'. Operating system error 5(Access is denied.).
[Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE is terminating abnormally.


Can anyone help me to tell me why it's occur and how to solve it...

Can anyone help me to tell me why it's occur

The file is locked and/or you just don't have proper privilege to access that file.

how to solve it...

You're dealing with SQL Server, right? SQL Server already has built-in backup/restore functionality and you can take advantage of that with T-SQL. You'll find everything about T-SQL in MSDN. Here's "How to: Create a Full Database Backup (Transact-SQL)" for SQL Server 2008 R2. Use MSDN's search to locate similar example for restoring database.

Finally, the "glue" between VB.NET and T-SQL comes from System.Data.SqlClient namespace. Do some googling and you'll find how to use connection and command objects to send T-SQL to SQL Server (unless you're already familiar with that).



How to open the lock or enable the database to the file or maybe i'm not aware that i locked it.

Can you explain to me the several reason i can't access the file..

The database engine runs under a user context. You can open services (Start->run->services.msc) and scroll down to SQL Server (MSSQL Server). Note the user under 'Log On As'. This user must have permissions to that directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.