我想打印我的报告,但是当我设置 server = (IP)\SQLEXPRESS 总是无法登录时,在管理工作室工作正常。如果我设置 server = .\SQLEXPRESS 它正在工作。为什么我不能使用 ip 将报表连接到数据库?
public class PrintService : IPrintService
{
readonly ReportDocument _reportDocument = new ReportDocument();
private readonly string _reportPath = ConfigurationManager.AppSettings["ReportPath"];
private readonly string _reportUser = ConfigurationManager.AppSettings["ReportUser"];
private readonly string _reportPassword = ConfigurationManager.AppSettings["ReportPassword"];
private readonly string _reportServer = ConfigurationManager.AppSettings["ReportServer"];
private readonly string _reportDatabase = ConfigurationManager.AppSettings["ReportDatabase"];
private readonly string _spbuNumber = ConfigurationManager.AppSettings["SPBUNumber"];
private readonly string _spbuAddress = ConfigurationManager.AppSettings["SPBUAddress"];
private readonly string _spbuPhone = ConfigurationManager.AppSettings["SPBUPhone"];
public void Print(string number, string reportName)
{
var path = _reportPath + reportName;
_reportDocument.Load(path);
_reportDocument.SetDatabaseLogon(_reportUser, _reportPassword, _reportServer, _reportDatabase);
_reportDocument.SetParameterValue("@Number", number);
_reportDocument.SetParameterValue("@Location", _spbuNumber );
_reportDocument.SetParameterValue("@Address", _spbuAddress);
_reportDocument.SetParameterValue("@Phone", _spbuPhone);
var print = new PrintDocument();
_reportDocument.PrintOptions.PrinterName = print.PrinterSettings.PrinterName;
_reportDocument.PrintOptions.PaperSize = (PaperSize) print.PrinterSettings.DefaultPageSettings.PaperSize.RawKind;
_reportDocument.PrintToPrinter(1, false, 1, 1);
}
}
谢谢 :)