如果我拿出連接字符串信息報告運行良好從我的機器,但任何其他用戶要求登錄信息,所以我想添加連接信息。不編譯的行是cr1.SetDatabaseLogon(connection, cr1);
Linq2sql Crystal報表的連接字符串。報告要求登錄
我在做什麼錯?任何幫助,將不勝感激!
private void launchReport(int pKReport)
{
using (DataClasses1DataContext db = new DataClasses1DataContext())
{
var query = (from s in db.expenseHdrs
join d in db.expenseDtls on s.rptNo equals d.rptNo
where s.rptNo == pKReport
from g in db.employees
join r in db.expenseHdrs on g.pk equals r.empPk
select new
{
s.period,
s.description,
s.department,
s.rptNo,
s.reimbursement, g.name,
d.expDate,
d.expType,
d.expDesc
});
CrystalReport1 cr1 = new CrystalReport1();
ConnectionInfo connection = new ConnectionInfo();
connection.DatabaseName = "intranet";
connection.UserID = "sa";
connection.Password = "*****";
cr1.SetDatabaseLogon(connection, cr1);
cr1.SetDataSource(query);
crystalReportViewer1.ReportSource = cr1;
}
}
我也試過我的查詢後的代碼更改爲以下但我仍然有相同的問題,因爲當我沒有連接字符串憑據之前。對除我自己以外的每個用戶,我都會得到相同的sql server登錄屏幕,無論我輸入什麼內容都會失敗。我認爲這是由於沒有數據庫名稱,它不會允許我手動輸入。
CrystalReport1 cr1 = new CrystalReport1();
cr1.FileName = @"C:\Intranet\CrystalReport1.rpt";
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "svr-sql";
connectionInfo.DatabaseName = "intranet";
connectionInfo.UserID = "sa";
connectionInfo.Password = "*****";
SetDBLogonForReport(connectionInfo, cr1);
cr1.SetDataSource(query);
crystalReportViewer1.ReportSource = cr1;
}
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo, CrystalReport reportDocument)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
如果您使用SQL Server管理工作室,您可以使用該用戶名和密碼組合登錄到其他數據庫? –