Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / February 2005

Tip: Looking for answers? Try searching our database.

Problem to restore an SQL database....

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rapha?l D?salbres - 27 Feb 2005 18:36 GMT
Hello,

I'm having the following problem.

I have SQL Server Accounting database called 'db_Accounting' , and a form.
This database is only accessed by one user at a time.
I have made a menu to backup the database. Works fine.

Dim fd As New SaveFileDialog
fd.Filter = "Database backup (BAK) | *.bak"
If fd.ShowDialog = DialogResult.OK Then
cmd.CommandText = "BACKUP DATABASE AccountingProgram TO DISK='" &
fd.FileName & "'"
cmd.ExecuteNonQuery()
End If

But then I need another menu to restore the database, but it doesn't work,
since the database is already in use.

Even if I try to close the connection it doesn't work.

What can I do about it? Do I have to kill an existing process?

Thanks,

Rapha?l D?salbres
Elton Wang - 27 Feb 2005 19:59 GMT
Hi Raphaël,

Although I 'm not sure, you can try to dispose the
connection after close it and then force Garbage
Collection:

Connection.Dispose();
GC.Collect();

HTH

Elton Wang
elton_wang@hotmail.com

>-----Original Message-----
>Hello,
[quoted text clipped - 25 lines]
>
>.
Bernie Yaeger - 27 Feb 2005 22:41 GMT
Hi Raphael,

You may want to take a look at using sqldmo and 2 functions they provide -
detach and attach database.

HTH,

Bernie Yaeger

> Hello,
>
[quoted text clipped - 22 lines]
>
> Rapha?l D?salbres
Rapha?l D?salbres - 27 Feb 2005 23:39 GMT
OK, thanks everybody...

> Hello,
>
[quoted text clipped - 22 lines]
>
> Rapha?l D?salbres
Jim Hughes - 27 Feb 2005 23:40 GMT
Be sure to change the connection string default database/initial catalog to
be something besides the database you are doing the backup/restore on.
Master is pretty common.

Also, show the syntax of the RESTORE command that you are using, If you are
replacing an existing database you will need to use the REPLACE option.

You may also need to use the MOVE option if you are changing the destination
location from the one that was used during the backup.

Also remember that the TO DISK option is relative to the SQL Server computer
itself and not the remote workstations hard drive, so using the
SaveFileDialog will only work if your app is run at the server.

> Hello,
>
[quoted text clipped - 22 lines]
>
> Rapha?l D?salbres

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.