Crystal报表部署连接到mdf文件

时间:2012-07-06 06:11:10

标签: c# crystal-reports

我在我的应用程序的bin / debug文件夹中复制了数据库的.mdf和.ldf文件,并使用了如下连接字符串

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True;User Instance=True

其中MyDatabase=database name 应用程序运行正常,但我在运行和创建设置文件后得到新的错误。我在设置项目中复制.mdf文件和.ldf文件,也在bin / release文件夹中,然后总应用程序运行正常,但现在我收到错误在水晶报告中询问用户名和密码。

请建议我这样做。

先谢谢。

public void Refreshreport()
{
   //I've added the report file (BalanceCrystalReport.rpt)to my project, 
   //and create an instance of the file. 
   var report = new BalanceCrystalReport();

   foreach (ReportDocument doc in report.Subreports)
   {
       foreach (Table table in doc.Database.Tables)
            table.ApplyLogOnInfo(MyTableLogOnInfo);

       doc.SetDatabaseLogon("","",".\\SQLEXPRESS","MyDatabase");
   }
   crystalReportViewer.ReportSource = report;
}

public virtual TableLogOnInfo MyTableLogOnInfo
{
  get
  {
      if(myTableLogOnInfo == null)
      {
         myTableLogOnInfo = new TableLogOnInfo();

         myTableLogOnInfo.ConnectionInfo.ServerName = ".\\SQLEXPRESS";
         myTableLogOnInfo.ConnectionInfo.DatabaseName = "MyDatabase";
         myTableLogOnInfo.ConnectionInfo.UserID = "";
         myTableLogOnInfo.ConnectionInfo.Password = "";
         myTableLogOnInfo.ConnectionInfo.IntegratedSecurity = true;
      }
  return myTableLogOnInfo;
 }

0 个答案:

没有答案