Should I use ExecuteNonQuery for this db backup command

后端 未结 8 872
迷失自我
迷失自我 2021-01-17 03:26

I have a method that allows me to kick off a back up of a data base. What I am wondering is if I should be using ExecuteNonQuery() in this context or if there is something

相关标签:
8条回答
  • 2021-01-17 04:04

    ExecuteNonQuery means that the command doesn't return any data. It doesn't mean that it executes asynchronously or that you won't receive error information. It will block until the command finishes and return any errors that may occur

    0 讨论(0)
  • 2021-01-17 04:04

    Try it. it resolved timeout expired problem while large size db.

    Private Sub Command1_Click() On Error Resume Next Dim con As New Connection Dim tm As String con.CommandTimeout = 500'''Command timeout should be 500

    With con .ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=dbiBMS;Data Source=192.168.103.4" .Open End With tm = CStr(Time)

    con.Execute " backup database dbiBMS to disk='E:\Database_Backup\Test1.bak' with format "

    con.Close MsgBox tm Exit Sub x: MsgBox Err.Description

    End Sub

    0 讨论(0)
  • 2021-01-17 04:08
    ExecuteNonQuery() 
    

    should be fine to use here. What I would do is run a try catch around the using to catch any errors that might happen and deal with them appropiately.

    0 讨论(0)
  • 2021-01-17 04:15

    You should use ExecuteNonQuery when you do not what to receive any information from the database as a result of your call. If any error with happen during execute of the command you will get a corresponding exception.

    0 讨论(0)
  • 2021-01-17 04:15

    I think ExecuteNonQuery is fine, but You should consider to user a timeout with Your query.

    objCommand.CommandTimeout = 60*60; // for an hour or more

    If You're using a desktop application, then for sure You should execute this query within asynchronous call.

    0 讨论(0)
  • 2021-01-17 04:25

    This does look like the type of thing you should put in a stored procedure to do some error handling.

    Also, have a look here to see it done in code.

    0 讨论(0)
提交回复
热议问题