Solved

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

Posted on 2010-08-15
3
515 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

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

Expert Comment

by:Alpha Au
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

734 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