如何解决“无法连接到服务器.\ sqlexpress." [英] How to Solve 'Failed to connect to server .\sqlexpress.'

查看:873
本文介绍了如何解决“无法连接到服务器.\ sqlexpress."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..
当我尝试使用c#从sqlserver 2005中备份数据库时,出现错误无法连接到服务器.\ sqlexpress.".我在DBBackup_click事件中使用的代码是:

hi..
When i am trying to take the backup of my database from sqlserver 2005 using c# ,it gives the error as "Failed to connect to server .\sqlexpress.". I have used the code in DBBackup_click event is :

Backup sqlBackup = new Backup();
       sqlBackup.Action = BackupActionType.Database;
       sqlBackup.BackupSetDescription = "ArchiveDataBase:" + DateTime.Now.ToShortDateString();
       sqlBackup.BackupSetName = "Archive";
       sqlBackup.Database = databaseName;
       BackupDeviceItem deviceItem = new BackupDeviceItem(destinationPath, DeviceType.File);
       //SqlConnection sqlCon = new SqlConnection("server=192.168.2.209;database=charity;uid=sa;pwd=pass");
       //ServerConnection connection = new ServerConnection(sqlCon);
       ServerConnection connection = new ServerConnection(serverName, userName, password);
       Server sqlServer = new Server(connection);
       Database db = sqlServer.Databases[databaseName];
       sqlBackup.Initialize = true;
       sqlBackup.Checksum = true;
       sqlBackup.ContinueAfterError = true;

       sqlBackup.Devices.Add(deviceItem);
       sqlBackup.Incremental = false;

       sqlBackup.ExpirationDate = DateTime.Now.AddDays(3);
       sqlBackup.LogTruncation = BackupTruncateLogType.Truncate;

       sqlBackup.FormatMedia = false;
       sqlBackup.SqlBackup(sqlServer);  /* Here, It throws the error */




谁能告诉我,如何解决该错误?




can anyone tell me , how to solve this error?

推荐答案

由于连接字符串损坏,无法将声音连接到我.
Failed to connect sounds to me like your connection string is broken.


阅读 [ ^ ]


这篇关于如何解决“无法连接到服务器.\ sqlexpress."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆