直接sqlconnection连接SQLSERVER,然后SQL脚本备份
解决方案 »
- Volatile 关键字不起作用
- 我在培训机构学,请问他们要系统全面的学,有这个必要吗,单学C#说不行,连JAVA都学,你们说有必要吗?那培训机构说不学JAVA倒他们面子。
- QuotedStr的替代函数
- 大容量文本文件的查询
- 请问各位高手都用什么集成测试工具
- C#能操作底层么??? 如监控U盘插入拔出、光驱监控的问题 进来看看
- vs2005机制又变了.微软总是在浪费大家的精力.
- 开机启动logo心得体会
- 求助一个简单的问题,对于我不是:) 在vs.net中怎么给c#生成的exe文件加上版权信息
- 都26了,还单身,找不到合适的,祝愿单身的朋友早日找到心目中的最爱,祝天下有情人Happy valentine's day!
- 用C#写一个简单的图片处理(把直线 给拾起)
- c#连接授时服务器
as declare @sql varchar(8000) if isnull(@dbname,'')='' set @dbname=db_name() if isnull(@bkfname,'')=''
set @bkfname='\DBNAME\_\DATE\_\TIME\.BAK' set @bkfname=replace(replace(replace(@bkfname,'\DBNAME\',@dbname),'\DATE\',convert(varchar,getdate(),112)),'\TIME\',replace(convert(varchar,getdate(),108),':',''))
update XTSZ set FNAME=@bkfname
set @sql='backup '+case @bktype when 'LOG' then 'log ' else 'database ' end +@dbname +' to disk='''+@bkpath+@bkfname +''' with '+case @bktype when 'DF' then 'DIFFERENTIAL,' else '' end+case @appendfile when 1 then 'NOINIT' else 'INIT' end
exec(@sql)
http://topic.csdn.net/u/20100422/16/5774810d-a6f9-4a2a-bcc9-977c709adaf9.html?80552
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DatabaseYDGL.mdf;Integrated Security=True;User Instance=True"这是备份数据库的SQL语句
SqlConnection Conn = DataConnection.MyConnection();
public void BackupDataBase()
{
string DataBaseName = "DatabaseYDGL";
string DataBaseOfBackupName = @"back.bak";
string DataBaseOfBackupPath = @"D:\Program Files\Microsoft SQL Server\MSSQL\Data\";
try
{
Conn.Open();
SqlCommand Comm = new SqlCommand();
Comm.Connection = Conn;
Comm.CommandText = "use master;backup database @dbname to disk = @backupname;";
Comm.Parameters.Add(new SqlParameter(@"dbname", SqlDbType.NVarChar));
Comm.Parameters[@"dbname"].Value = DataBaseName;
Comm.Parameters.Add(new SqlParameter(@"backupname", SqlDbType.NVarChar));
Comm.Parameters[@"backupname"].Value = @DataBaseOfBackupPath + @DataBaseOfBackupName;
Comm.CommandType = CommandType.Text;
Comm.ExecuteNonQuery();
MessageBox.Show("备份数据库成功", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
Conn.Close();
}
}
这是错误信息
这个问题怎么解决啊...