Solved

providing sql username & password to crystal report in asp.net c#

Posted on 2010-08-15
3
508 Views
Last Modified: 2012-05-10
i have a crystal report in asp.net & c#

the rpt file has the sql query with groupings as i require

what i want to do is to provide ONLY the sql username & password using C# code

please note i want to supply just the username & password... NOT wanting to fill the report with a dataset or whatever
CrystalReportViewer1.ReportSource = "BrokerageConsolidatedMonthHO.rpt";

CrystalReportViewer1.SelectionFormula = "Month ({table1.cmonth})=5" + ;

Open in new window

0
Comment
Question by:RakeshBhandari
3 Comments
 
LVL 14

Accepted Solution

by:
Dhanasekaran Sengodan earned 500 total points
ID: 33443603
0
 
LVL 7

Expert Comment

by:alphaau
ID: 33443765
Please refer to the enclosed method, it can change the datasource, userid, password and databasename of a ReportDocument (support sub-report)

and you can get there information from web.config
            System.Data.SqlClient.SqlConnectionStringBuilder SConn = new System.Data.SqlClient.SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
           
            SetCRLogOnInfo(rptDoc, SConn.DataSource, SConn.UserID, SConn.Password, SConn.InitialCatalog);
        public void SetCRLogOnInfo(ReportDocument mainInRD, string dataSource, string userId, string pwd, string DatabaseName)

        {

            //do the main reports database

            TableLogOnInfo logonInfo = null;



            foreach (CrystalDecisions.CrystalReports.Engine.Table table in mainInRD.Database.Tables)

            {

                logonInfo = table.LogOnInfo;

                logonInfo.ConnectionInfo.ServerName = dataSource;

                logonInfo.ConnectionInfo.DatabaseName = DatabaseName;

                logonInfo.ConnectionInfo.UserID = userId;

                logonInfo.ConnectionInfo.Password = pwd;

                table.ApplyLogOnInfo(logonInfo);

            }

            try

            {

                //now update logon info for all sub-reports

                if (!mainInRD.IsSubreport && mainInRD.Subreports != null && mainInRD.Subreports.Count > 0)

                {

                    foreach (ReportDocument rd in mainInRD.Subreports)

                    {

                        SetCRLogOnInfo(rd, dataSource, userId, pwd, DatabaseName);

                    }

                }

            }

            catch

            {

            }

        }

Open in new window

0
 
LVL 2

Author Closing Comment

by:RakeshBhandari
ID: 33498453
thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now