DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   VB.NET (http://www.daniweb.com/forums/forum58.html)
-   -   Backup of sql server using vb.net code (http://www.daniweb.com/forums/thread138585.html)

dhanashreegd Aug 5th, 2008 5:45 am
Backup of sql server using vb.net code
 
Dim strSql As String
strSql = " set quoted_identifier off "
strSql &= " declare @strSql varchar(150) "
strSql &= " set @strSql = ""BackUp database SWAMC to disk = 'D:\SWAMC"" + Convert(varchar, getdate(), 112) + Replace(Convert(varchar, getdate(), 108), "":"", """") + "".dbb' with init,skip"""
strSql &= " print @strSql"
strSql &= " exec (@strSql) "
strSql &= "set quoted_identifier on "

Dim SqlCmd As New SqlClient.SqlCommand(strSql, con)
SqlCmd.ExecuteNonQuery()


this give me error in taking backup
Plz help me...................................

pacificcode Aug 5th, 2008 11:12 pm
Re: Backup of sql server using vb.net code
 
Hi,

When trouble shooting VB & SQL I always find it easier to formulate my string variable "strSql" and then output this text to a text message.

Then copy this text string and manually run the string using T-SQL or from the SQL 2005 interface.

This will show if your syntax is being assembled correctly by pointing out where the SQL server is having a problem with the command.

If it runs OK manually, then that would mean that you are not sending it over to SQL in the proper format and you may have issues with " or ' or ''' other related formatting & spacing issues.

Good luck..!
MJ


All times are GMT -4. The time now is 3:42 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC