1

レポートを印刷したいのですが、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);
    }
}

ありがとう :)

4

2 に答える 2

0

IS (IP) は server namme または ip address 、id Ip はサーバー名です。括弧を削除します。または、そのサーバーの直接の IP アドレスを使用します。

于 2013-02-06T09:30:57.487 に答える
0

クライアント PC で実行時にレポートを読み込むには、接続文字列を調べて、クライアントのローカル サーバー名を見つける必要がありました。Crystal Reportフォームのログオン接続を変更するさまざまな方法を試しましたが、これだけがうまくいきました.これは、最新の13.0.9.1312.Cortez_CR4VSバージョンで、WindowsフォームバージョンがWPF内にあります。このコードでは、prepap はパスを含む完全な Crystal レポート名であり、dbName は接続された SQL データベースの名前だけです。csName は app.config からのものです: 追加名の文字列。新しい接続がレポートに保存されます。

ReportDocument doc = new ReportDocument();
String CS = (String)ConfigurationManager.ConnectionStrings[csName].ConnectionString;
doc.Load(prerap);
String DS = CS.Substring(12 + CS.IndexOf("data source"), CS.IndexOf("SQLEXPRESS") - CS.IndexOf("data source") - 2);
            if (doc.DataSourceConnections[0].ServerName != DS)
            {
                for(int i=0;i<doc.DataSourceConnections.Count;i++) 
                {
                    doc.DataSourceConnections[i].SetConnection(DS, dbName, true);               
                }

                doc.SaveAs(prerap);

            }
于 2014-07-19T11:12:56.430 に答える