Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:54:54+00:00 2026-05-29T14:54:54+00:00

I am attaching My DB through vb.net code. Now I request help for the

  • 0

I am attaching My DB through vb.net code.

Now I request help for the following:

  1. How to detach it using code (uid=sa, pwd=abc123)?
  2. How to take backup?
  3. How to restore backup?

Please note I want to do it all using vb.net code

Thanks a lot.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:54:55+00:00Added an answer on May 29, 2026 at 2:54 pm

    Backup:

    USE AdventureWorks2008R2;
    GO
    BACKUP DATABASE AdventureWorks2008R2
    TO DISK = 'Z:\SQLServerBackups\AdventureWorks2008R2.Bak'
       WITH FORMAT,
          MEDIANAME = 'Z_SQLServerBackups',
          NAME = 'Full Backup of AdventureWorks2008R2';
    GO
    

    Restore:

    ----Put database into single user mode (terminates open connections - else restore fails)
    ALTER DATABASE YourDB
    SET SINGLE_USER WITH
    ROLLBACK IMMEDIATE
    
    
    RESTORE DATABASE YourDB 
    FROM DISK = 'D:\temp\YourDB.bak' 
    WITH REPLACE 
    ,MOVE 'YourDB_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\YourDB_Data.mdf'
    ,MOVE 'YourDB_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\YourDB_Data.ldf'
    
    
    ALTER DATABASE YourDB SET MULTI_USER
    GO
    

    Detach:

    EXEC master.dbo.sp_detach_db @dbname = N'AdventureWorks',
    @keepfulltextindexfile = N'true'
    GO
    

    Attach:

    EXEC master.dbo.sp_attach_db @dbname = N'AdventureWorks2008R2', 
        @filename1 = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\AdventureWorks2008R2_Data.mdf', 
        @filename2 = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Data\AdventureWorks2008R2_log.ldf';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attaching a new database programatically using VB.net application. I wrote DB scripts and
Is there an advantage to dynamically attaching/detaching event handlers? Would manually detaching handlers help
How does one go about attaching a bunch of code to an onkeydown event,
I'm trying to upload documents to SharePoint using web services attaching custom metadata to
I've been using the macro from this blog entry for attaching the Visual Studio
I am interested in a profiler that is capable of attaching to a .NET
I am looping through a Javascript array, attaching events to elements by ID. I
In the following function it goes through the if and the else, why is
I guess that this is a really stupid question, knowing that .net-code can be
I'm following the Sports Store example in Pro ASP.NET MVC Framework and I'm getting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.