简体   繁体   English

如何显示水晶报表?

[英]How to display Crystal Report?

I am getting this error while displaying crystal report. 显示水晶报表时出现此错误。 what do i need to do. 我需要做什么。

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

Code i am using is as follows : 我使用的代码如下:

protected void Page_Load(object sender, EventArgs e)
{        
    SqlConnection con = new SqlConnection("Data Source=./SQLEXPRESS;AttachDbFilename=~/App_Data/Database.mdf;Integrated Security=True;User Instance=True");        
    DataSet1 ds = new DataSet1();
    SqlDataAdapter da = new SqlDataAdapter("SELECT        ID, Name, Dept, Salary FROM            dbo.Table2", con);
    da.Fill(ds.View2);
    ReportClass myReportObject = new ReportClass();
    myReportObject.ResourceName = "CrystalReport1.rpt";        
}

I Think your Crystal report you are trying to display has been made under an another Connection string has an another Server name. 我认为您要显示的Crystal报表是在另一个Connection字符串和另一个Server名称下创建的。 pass Server name and database name separately to the report. 将服务器名称和数据库名称分别传递给报告。 the code will helpful. 该代码将有所帮助。

        ReportDocument cryRpt = new ReportDocument();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables ;

        cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

        crConnectionInfo.ServerName = "YOUR SERVER NAME";
        crConnectionInfo.DatabaseName = "YOUR DATABASE NAME";

       // if sql server authentication mood

        crConnectionInfo.UserID = "YOUR DATABASE USERNAME";
        crConnectionInfo.Password = "YOUR DATABASE PASSWORD";

        CrTables = cryRpt.Database.Tables ;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }

        crystalReportViewer1.ReportSource = cryRpt;
        crystalReportViewer1.Refresh(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM