我正在使用代码将ConnectionInfo发送到crystalReportViewer
private void button1_Click(object sender, EventArgs e)
{
ConnectionInfo myConnectionInfo = new ConnectionInfo();
myConnectionInfo.ServerName = "192.168.3.58";
myConnectionInfo.DatabaseName = "SHRK-Traffic";
myConnectionInfo.UserID = "sa";
myConnectionInfo.Password = "pass";
setDBLOGONforREPORT(myConnectionInfo);
crystalReportViewer1.Visible = true;
}
private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
{
TableLogOnInfos mytableloginfos = new TableLogOnInfos();
mytableloginfos = crystalReportViewer1.LogOnInfo;
foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
{
myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
}
}
我在网络应用中使用此代码并且工作正常..但在Windows应用中它显示错误
error http://i54.tinypic.com/104kymv.jpg
我收到了错误
答案 0 :(得分:1)
您需要创建一个TableLogOnInfo对象,然后将它的ConnectionInfo对象设置为正确的信息,即:
TableLogOnInfo loginDetails = new TableLogOnInfo();
loginDetails.ConnectionInfo.ServerName = "ALFA1\\ACMSDB";
loginDetails.ConnectionInfo.UserID = "***";
loginDetails.ConnectionInfo.Password = "***";
loginDetails.ConnectionInfo.DatabaseName = "database";
loginDetails.ConnectionInfo.IntegratedSecurity = false;
然后继续将配置好的TableLogOnInfo对象添加到LogOnInfo集合中:
crystalReportViewer1.LogOnInfo.Add(loginDetails);