2
votes

I got problem in providing the User Id and Password in Crystal Report of Windows Form. I used Windows Authentication when connecting to SQL Server and sometimes use the sa account with sql server authentication. So I tried the Server name with a blank password but it failed. I also try the sa login of sql server authentication providing the same password I used when I'm connecting to sql server. Is User Id different from Login Name of sqlserver? How will I provide the User Id and password in Crystal Reports?

I also try to add dynamic logon parameter with UserID as sa and with it's password. But still failed.

I already know how to connect my application in database but I think it is different from crystal reports.

2

2 Answers

0
votes

Hope you are using Report document and here is the C# code snippet to set the connection on the fly. You may need to traverse through the sub reports as well to set the connections if any

for (int i = 0; i < reportDocument.DataSourceConnections.Count; i++)
                {
                    reportDocument.DataSourceConnections[i].SetConnection(Server.Name, Database.Name, Server.User.Name,Server.User.Password);
                    reportDocument.DataSourceConnections[i].SetLogon(Server.User.Name, Server.User.Password);
                }
0
votes

Hi Kindly check out the code snippet below, that is how i set my database connection when using crystal reports.Hope it helps.

            ReportDocument cryRpt = new ReportDocument();
            TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
            TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
            ConnectionInfo crConnectionInfo = new ConnectionInfo();
            Tables CrTables;

            cryRpt.Load(Application.StartupPath + "\\CrystalReport1.rpt");


            crConnectionInfo.ServerName = "server Name";
            crConnectionInfo.DatabaseName = "Database Name";
            crConnectionInfo.UserID = "sa";
            crConnectionInfo.Password = "****";

            CrTables = cryRpt.Database.Tables;
            foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
            {
                crtableLogoninfo = CrTable.LogOnInfo;
                crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                CrTable.ApplyLogOnInfo(crtableLogoninfo);
            }