Skip to Content
0
Former Member
Aug 23, 2012 at 10:58 PM

Linq2sql Connection string for crystal report. Report requires logon

17 Views

If I take out the connection string info the report runs fine from my machine but any other user it asks for logon information so I am trying to add the connection info. The line that is not compiling is `cr1.SetDatabaseLogon(connection, cr1);`

What am I doing wrong? Any help would be appreciated!

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;

}

}

I also tried changing the code after my query to below but I still have the exact same problem as before when I didnt have the connection string credentials. On every user but myself I get the same sql server login screen and no matter what I enter it fails. I think it is due to there being no database name which it will not allow me to manually enter.

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);

}

}

Attachments

Capture.PNG (17.3 kB)