crystal reports connection strings
hi..
i want to override the connection string of crystal reports..
is there any way that i use the connection string as shared datasource.
MY PROBLEM BEGINS:
i've 50 reports with the connection string vsspl-005\sqlexoress
but i've changed my connection string vsspl-002\sqlexpress.
there is only one way that i dont want to do i.e individually change the connection string of each crystal report
using database experts..
is there any way that the connection string should be assigned as shared datasource..
or any other way..
Please please help me i'm trying this since from one week..
inform me whether it is possible or not.
if possible send me the code..
if not.. then reason please.
i'm fedup of this..
Re: crystal reports connection strings
Sure there is a way to change the datasource at running time when call a crystal reports' rpt file
Please, say Crystal Reports version and prog.language version
Also, post the code where you are calling and printing the rpt
JG
Re: crystal reports connection strings
The below is my code which is in page load. it works well when i remove the if(!ispostback) condition it means that
it will hit the database many times.
if i keep this it works only while page loading when i give print or next page, a logon prompt will appear and
ask the user name and passward of the old connection string which i dont want...
please help me and correct the code..
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();
ReportDocument myreport = new ReportDocument();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
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];
myreport.Load(MapPath("~/" + "emp.rpt"));
// myreport.Database.Tables[0].ApplyLogOnInfo(LogInfo);
myreport.Database.Tables[0].SetDataSource(td);
CrystalReportViewer1.ReportSource = myreport;
Logininfo();
//int count = Convert.ToInt32(dt.Tables[0].Rows.Count);
myConnection.Close();
}
}
//}
private void Logininfo()
{
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
//ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
CrystalReportViewer1.LogOnInfo = new CrystalDecisions.Shared.TableLogOnInfos();
// ReportDocument myreport = new ReportDocument();
CrTables = myreport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo.ConnectionInfo.ServerName = "VSSPL-002\\SQLEXPRESS";
crtableLogoninfo.ConnectionInfo.DatabaseName = "employee";
crtableLogoninfo.ConnectionInfo.UserID = "sa";
crtableLogoninfo.ConnectionInfo.Password = "sa@123";
//crtableLogoninfo.ConnectionInfo.ServerName = ConfigurationManager.AppSettings["ServerName"];
//crtableLogoninfo.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["DatabaseName"];
//crtableLogoninfo.ConnectionInfo.UserID = ConfigurationManager.AppSettings["UserName"];
//crtableLogoninfo.ConnectionInfo.Password = ConfigurationManager.AppSettings["Password"];
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.LogOnInfo.Add(crtableLogoninfo);
}