locked
changing datasource connection RRS feed

  • Question

  • User-1232439801 posted

    hi...

    i've 50 crystal reports which is connected to the database directly without using any dataset..

    and the connection string is vsspl-002\\sqlexpress..

    now my problem is i've shifted the database to another location..

    and my connection string is vsspl-008\\sqlexpress..

    now i dont want to change the connection string for each report individually..

    is there any solution that to change only once and it apply to all the reports...

    please help me it urgent....

    Wednesday, September 15, 2010 12:35 AM

All replies

  • User-1802908944 posted

    if you are using connectionstring from web.config or any common file which is shared by all report then you can change connectionstring only that file only other wise you need to do manully.


    Wednesday, September 15, 2010 5:55 AM
  • User-1232439801 posted

    Error    2    'System.Web.HttpApplicationState' does not contain a definition for 'startuppath' and no extension method 'startuppath' accepting a first argument of type 'System.Web.HttpApplicationState' could be found (are you missing a using directive or an assembly reference?)    E:\Report1\global\Default.aspx.cs    77    36    E:\Report1\global\


     please help me..
    i want to override the connection string of crystal reports which was connected by the database experts..
    now i want to override with with new connection string .. the above error is diaplaying..
    the following is my code if there is any mistake please correct me...
    its urgent  please help me....

    the code is..
    using System;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Data.SqlClient;
    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    using System.Data.OleDb;
    using CrystalDecisions.Enterprise;


    public partial class _Default : System.Web.UI.Page
    {
        string connections = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
        private TableLogOnInfo LogInfo = new TableLogOnInfo();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

             

              }


        }



        private void SetLogonInfo()
        {
            try
            {
                LogInfo.ConnectionInfo.ServerName = "";
                LogInfo.ConnectionInfo.UserID = "";
                LogInfo.ConnectionInfo.Password = "";
                LogInfo.ConnectionInfo.DatabaseName = "";
            }
            catch (Exception e)
            {
                
            }
        }
        //private void setDBLOGONforREPORT(ConnectionInfo myconnectioninfo)
        //{
        //    TableLogOnInfos mytableloginfos = new TableLogOnInfos();
        //    mytableloginfos = CrystalReportViewer1.LogOnInfo;
        //    foreach (TableLogOnInfo myTableLogOnInfo in mytableloginfos)
        //    {
        //        myTableLogOnInfo.ConnectionInfo = myconnectioninfo;
        //    }

        //}

          protected void btn_emp_Click(object sender, EventArgs e)
        {
            // string connections = ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString;
            // string connections = "Data Source=VSSPL-002\\SQLEXPRESS;Initial Catalog=employee;Integrated Security=True";
            string myQuery = "select * from employee";
            SqlConnection myConnection = new SqlConnection(connections);
            SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
            myCommand.Connection.Open();
            SqlDataAdapter da = new SqlDataAdapter(myCommand);
            DataSet dt = new DataSet();
            da.Fill(dt);
            DataTable td = dt.Tables[0];
     
             ReportDocument myreport = new ReportDocument();
             string path = Application.startuppath + "~/" + "emp.rpt";
             myreport.Load(path);
             myreport.Database.Tables[0].ApplyLogOnInfo(LogInfo);
             myreport.SetDataSource(td);
             CrystalReportViewer1.ReportSource = myreport;
              // myreport.Load(MapPath("~/" + "emp.rpt"));
             //myreport.Database.Tables[0].SetDataSource(td);
             //CrystalReportViewer1.ReportSource = myreport;
             //int count = Convert.ToInt32(dt.Tables[0].Rows.Count);
             myConnection.Close();
              
          }


    Thursday, September 16, 2010 1:04 AM