Click here to Skip to main content
15,916,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..
Posted

1 solution

 
Share this answer
 
Comments
vinu.1111 21-Sep-10 0:31am    
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);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900