I see similar topics have been discussed in places and non of the answers i found solves my problem. CrystalReport document I open in CR Viewer in a form in my development machine. When I deployed it in another pc which has to access a production database on another server. I used the following code to set the connection info dynamically.
ReportDocument rpt = new ReportDocument(); ConnectionInfo ci = new ConnectionInfo(); TableLogOnInfos tis = new TableLogOnInfos(); TableLogOnInfo ti = new TableLogOnInfo(); Tables crTbls; rpt.Load(c.appPath + @"\reports\report1.rpt"); ci.DatabaseName = dataBase; ci.ServerName = dbServer; ci.UserID = userName; ci.Password = userPassword; crTbls = rpt.Database.Tables; foreach (Table crTbl in crTbls) { ti = crTbl.LogOnInfo; ti.ConnectionInfo = ci; crTbl.ApplyLogOnInfo(ti); } crViewer.ReportSource = rpt; crViewer.RefreshReport();
But, when deployed, the report contineously prompt for user name password. In the login prompt, I see the server is pre-filled with value passed aboveand disabled but the database is disables and empty. username and password fields pre-filled with values passed above.
This method works on few other reports. Only different is this report uses a "SQL View" instead of accessing the table directly. Am I missing something here? Or is there any other way to set connection values dynamically?
Thank you in advance
Message was edited by: Riyad Salam Ok, I added rpt.Refresh() just before setting the ReportSource to crViwer. It seems to work now. Currently doing few tests. rpt.Refresh(); crViewer.ReportSource = rpt; crViewer.RefreshReport();