Backup my web application with Database.

Last post 06-13-2008 7:56 AM by jasonsky. 8 replies.

Sort Posts:

  • Backup my web application with Database.

    06-06-2008, 12:32 AM
    • Loading...
    • jasonsky
    • Joined on 01-07-2004, 5:17 AM
    • Posts 124

    I have finished my web application and now, it is going to deploy to a real server.  However, my another concern is BackUp the Database. 

    I try to use third-party software to do Backup process, but everytime it runs the backup, it logs the error: "There has been a sharing violation".  How can I solve the problem to backup Database file during the web application running.

     Many thanks.

    Jason

  • Re: Backup my web application with Database.

    06-06-2008, 1:15 AM

    It would be a good idea to tell us which database product you are using, Sql Server, Oracle, etc. ... Smile

    If this answered your question, be sure to mark it as the answer. That way, everybody after you will know it's the answer also!
  • Re: Backup my web application with Database.

    06-06-2008, 12:28 PM
    • Loading...
    • jasonsky
    • Joined on 01-07-2004, 5:17 AM
    • Posts 124

    I am using SQL Server.

  • Re: Backup my web application with Database.

    06-09-2008, 2:22 AM

    Hi,

    You can write T-SQL and execute this T-SQL in your ASP.NET project or in another application such as Windows Services to backup your Database.

    You can execute this T-SQL using SqlConnection, ExecuteNonQuery on SqlCommand.

    For example:

    USE master
    GO
    EXEC sp_addumpdevice 'disk', 'AdvWorksData', 
    'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\BACKUP\AdvWorksData.bak';
    GO
    BACKUP DATABASE AdventureWorks 
     TO AdvWorksData
       WITH FORMAT;
    GO
     
    For more information, see http://msdn.microsoft.com/en-us/library/ms188409.aspx
     
    I hope this helps.
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Backup my web application with Database.

    06-13-2008, 2:07 AM
    • Loading...
    • jasonsky
    • Joined on 01-07-2004, 5:17 AM
    • Posts 124

    Hi,

     I tried to write the following code, but it returns: "Could not locate entry in sysdatabases for database 'MyDB'. No entry found with that name.  Make sure that the name is entered correctly.  BACKUP DATABASE is terminating abnormally."  I am sure the connection is correct.  Any idea with this?  Thanks. 

     

            Dim myConnection As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ToString)
            Dim myCommand As New SqlClient.SqlCommand
            myConnection.Open()

            myCommand.Connection = myConnection
            myCommand.CommandText = "BACKUP DATABASE [MyDB] TO DISK = N'D:\MyDB.BAK' WITH FORMAT"
            myCommand.ExecuteNonQuery()


            myConnection.Close()
            myConnection.Dispose()

  • Re: Backup my web application with Database.

    06-13-2008, 3:48 AM

    Hi,

    The error message indicates that the db name (MyDB) does not exist in sysdatabases. You check in SSMS by expanding the database node and see if it exist or execute the below query to see if the db is present there:

    Select name from master.sysdatabases where name='MyDB'

     

    I hope this helps.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Backup my web application with Database.

    06-13-2008, 5:43 AM
    • Loading...
    • jasonsky
    • Joined on 01-07-2004, 5:17 AM
    • Posts 124

    Dear,

     I tried to run your code, but it shows: Invalid object name 'master.sysdatabases'.   I have no idea to solve my problem.  In fact, I am junior in SQL Server.  So, I try to post my information as details as possible, so that you can give me advice.

     I am using VWD Express 2005 to program a web application with a DB under SQLExpress.  My code for the connection between web application and DB as follows:

    <add name="MyConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

     In the Database Explorer of VWD, I only find my DB file: MyDB.mdf

    Any idea about that?  Thanks.

     

     

     

     

  • Re: Backup my web application with Database.

    06-13-2008, 6:12 AM

    Hi,

    I am sorry. It should be "Select name from master..sysdatabases where name='MyDB'".

     

    I hope this helps.

     

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: Backup my web application with Database.

    06-13-2008, 7:56 AM
    • Loading...
    • jasonsky
    • Joined on 01-07-2004, 5:17 AM
    • Posts 124

    It does not prompt error message now and return the following message.. then, what should I do for running the backup code?

     

    Running [dbo].[TryOnly].

    name                                                                                                                            
    --------------------------------------------------------------------------------------------------------------------------------
    No rows affected.
    (0 row(s) returned)
    @RETURN_VALUE = 0
    Finished running [dbo].[TryOnly].

Page 1 of 1 (9 items)
Microsoft Communities
Page view counter