I am Publishing crystal reports on remote server using the following code. when i try to run the crystal report page Crystal report viewer prompt me for database info. As the published crystal report were created using development server. In my crystal report i was using OLEDB ADO Connection
MyRepository _MyRepository = new MyRepository();
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
System.Data.SqlClient.SqlCommand MyCommand = new System.Data.SqlClient.SqlCommand("dbo.spMySP");
MyCommand.Connection = myConnection;
MyCommand.Parameters.Add("#PositionID", SqlDbType.Int).Value = (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue));
MyCommand.CommandType = System.Data.CommandType.StoredProcedure;
System.Data.SqlClient.SqlDataAdapter MyDA = new System.Data.SqlClient.SqlDataAdapter();
MyDA.SelectCommand = MyCommand;
ASale _DS = new ASale();
MyDA.Fill(_DS, "dbo.spMySP");
rptSale oRpt = new rptSale();
oRpt.SetDatabaseLogon("sa", "mypass");
oRpt.SetDataSource(_DS);
oRpt.SetParameterValue(0, "param1");
oRpt.SetParameterValue(1, "param2");
oRpt.SetParameterValue(2, "param3" );
oRpt.SetParameterValue(3, (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue)));
CrystalReportViewer1.ReportSource = oRpt;
HI,
When you develop your report, do you use Windows authentication to login to the database to build the report?
Maybe you can try to open the report again and try to update your database set up on the crystal report. E.g. by using the same login information your use on your code.
What I normally do is to put the database server name and the database name on to the code as well
E.G.
_CReportDoc.SetDatabaseLogon(username, pw, ServerName, DB)
Not sure if it could help
Related
I need to execute a .rss SSRS script file within an ASP.NET application running in IIS 7.x. How can I do that?
Do I have to configure the IIS AppPool that is running my web application to have elevated privileges such that I can start up the rs.exe console application passing the .rss script to it the way I would otherwise execute an .rss script file outside of IIS?
Or is there another way? Does Visual Studio/.NET provide any mechanism for bootstrapping an .rss script file without needing the rs.exe console application? Is my only option to make the rs.exe console application available to my web application running in IIS?
So, I figured it out. If you're wondering how to create a History Snapshot of a report on your SSRS Reports Server using the ReportServices2010 proxy, here's one example and one way you can accomplish it (many thanks to kyzen for sharing his insight in directing me to the SOAP API):
Dim basicHttpBinding As New BasicHttpBinding()
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm
basicHttpBinding.SendTimeout = New TimeSpan(0, 10, 0)
Dim endPoint As New EndpointAddress("http://server/reportserver/ReportService2010.asmx")
Dim instance As New ReportingService2010SoapClient(basicHttpBinding, endPoint)
Dim itemPath As String = "/Path/to/report"
Dim warnings() As Warning
Dim historyId As String = Nothing
Dim values As ParameterValue() = Nothing
Dim credentials As DataSourceCredentials() = Nothing
Dim t As New TrustedUserHeader()
instance.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation
instance.ClientCredentials.Windows.ClientCredential = New Net.NetworkCredential("userid", "password", "domain")
instance.Open()
oServerInfoHeader = instance.CreateItemHistorySnapshot(t, itemPath, historyId, warnings)
and in C#:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm
basicHttpBinding.SendTimeout = New TimeSpan(0, 10, 0)
EndpointAddress endPoint = new EndpointAddress("http://server/reportserver/ReportService2010.asmx");
ReportingService2010SoapClient instance = new ReportingService2010SoapClient(basicHttpBinding, endPoint);
string itemPath = "/Path/to/report"
Warning warnings[];
string historyId;
ParameterValue values[];
DataSourceCredentials credentials[];
TrustedUserHeader t = new TrustedUserHeader();
instance.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
instance.ClientCredentials.Windows.ClientCredential = New Net.NetworkCredential("userid", "password", "domain");
instance.Open();
oServerInfoHeader = instance.CreateItemHistorySnapshot(t, itemPath, historyId, warnings);
i have tried almost everything I could. I have a web app in ASP.net with c#. I am fetching data from the database tables and adding it to dataset. Then I set this dataset as the source to the report. My code is as following.
con.ConnectionString = ConfigurationManager.ConnectionStrings["familyConnectionString"].ConnectionString;
SqlDataAdapter sda = new SqlDataAdapter("select uid, member_name, gender, dob from family where uid='"+uid+"'", con);
DataSet1 myds = new DataSet1();
sda.Fill(myds, "family");
SqlDataAdapter sda1 = new SqlDataAdapter("select id from birth_certificates where p_id='"+uid+"'", con);
sda1.Fill(myds, "birth_certificates");
ReportDocument rpt = new ReportDocument();
rpt.Load(Server.MapPath("birth_certi_report.rpt"));
rpt.Refresh();
rpt.SetDataSource(myds);
rpt.SetDatabaseLogon("","",#".\sqlexpress","project2");
CrystalReportViewer1.ReportSource = rpt;
CrystalReportViewer1.DataBind();
CrystalReportViewer1.Visible = true;
CrystalReportViewer1.RefreshReport();
I am using integrated security so I left username and password blank. Please help.
Please Note that the above code is written inside a DropDown_selectedIndexChanged() event. I tried adding it to the page_load but it didn't work.
If you are not worried about authentication ,then do it this way.Create an instance of your crystal report and set its data source.Thats all you need to do and it works.
*Make sure the crystal report is within your solution.
con.ConnectionString = ConfigurationManager.ConnectionStrings["familyConnectionString"].ConnectionString;
// the magic
birth_certi_report myreport = new birth_certi_report();
DataSet1 myds = new DataSet1();
SqlDataAdapter sda1 = new SqlDataAdapter("select id from birth_certificates where p_id='"+uid+"'", con);
sda1.Fill(myds, "birth_certificates");
myreport.SetDataSource(myds);
crystalReportViewer1.ReportSource = myreport;
birth_certi_report myreport = new birth_certi_report();
in this line you have mentioned that birth_certi_report is crystal report. my crystal report name is applicationreport but it shows an error.
Dim myreport As New appilcationreport
error is TYPE IS NOT DEFINED
When I execute this code:
AdomdConnection con = new AdomdConnection("Data Source=MyServer;User ID=MyDomain\\MyUserName;Password=MyPassword");
con.Open();
con.ChangeDatabase("Analysis Services Project1");
I get this exception:
Either the user, MyDomain\MyUserName$, does not have access to the
Analysis Services Project1 database, or the database does not exist.
The database name comes from looking at the server using Microsoft SQL Server Management Studio. If I bring up the properties on the server and go to the security section, my account is listed as a Server administrator. While in management studio, I can see data sources, cubes and execute mdx queries fine.
Why can't do I get this exception in code?
whihc line causes the error?
I imagine you have to infor the catalog on your connection string. Try addind
Catalog=Analysis Services Project1
to your con string.
Also, Analysis Services Project1 seems to be the projects name? Are you sure this is the database name as well?
First
added the reference for Microsoft.AnalysisServices.AdomdClient.dll
strCon = "Data Source=DBserverServerName;Integrated Security=SSPI;Initial Catalog=DBName;";
AdomdConnection con = new AdomdConnection("connectionstring"); // connect DB con.Open(); AdomdCommand cmd = new AdomdCommand("MDX query", con); //query
AdomdDataReader reader = cmd.ExecuteReader(); //Execute query
while (reader.Read()) // read
{
Data dt = new Data(); // custom class
dt.Gender = reader[0].ToString();
dt.Eid = reader[1].ToString();
dt.salary = reader[2].ToString();
data.Add(dt);
}
I have a problem with my crystal reports in Visual Studio 2008, and after searching and searching I got nothing.
My file CrystalReportxxx.rpt has an xsd file as dataschema. A datatable is created and it's passed to report as datasource. To fill the datatable, my application connects to Oracle database.
For showing rows or data with CrystalReportViewer, the report needs credentials like logid and password of database. However, if I export this report to a PDF file, then no credentials are needed and PDF file shows all rows.
This is my code:
Dim dt As DataTable
FunctionsOP.CreaDataTable("pkg_list.sp_list", True, ospEntry,
dt)
Dim oRpt As New Reportes.CrystalReportxxx
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
oRpt.SetDataSource(dt)
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
I suppose that when setting:
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
and report shows no data, is because credentials are wrong.
My question is: How to bypass this credential input?
Is it mandatory to input userid, password, etc for using a xsd file in my Crystal
Report?
What is strange to me is that when I export that report to PDF, there is no
problem. Data is shown OK and no credential is needed:
Dim exportOpts As ExportOptions = oRpt.ExportOptions
oRpt.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat
oRpt.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile
oRpt.ExportOptions.DestinationOptions = New
DiskFileDestinationOptions
CType(oRpt.ExportOptions.DestinationOptions,
DiskFileDestinationOptions).DiskFileName = Server.MapPath("../Temp/" +
PDFName)
oRpt.Export()
oRpt.Close()
oRpt.Dispose()
I also tried this code:
Dim dt1 As New DataTable : Dim dt2 As New DataTable
Dim oRpt As New Reportes.CR_IndicadorA11
Dim ParRep As ReportClass = oRpt
SetConnectionsReports(ParRep)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_sum", True, Nothing, dt1)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_det", True, Nothing, dt2)
oRpt.SetDataSource(dt1)
oRpt.OpenSubreport("CR_sub_indicadorA11_det.rpt").SetDataSource(dt2)
CrystalReportViewer1.Visible = True
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
Public Sub SetConnectionsReports(ByRef Rpt As ReportClass)
Dim server, base, user, pass As String
server = "SRVBDDESA2.DOMINTERN0XXX.LOCAL" ' also with IP number is the same
base = "DESAOPINT"
user = "ORGPOL"
pass = "desarrollo"
For Each connection As IConnectionInfo In Rpt.DataSourceConnections
connection.SetConnection(server, base, user, pass)
Next
End Sub
I am converting an ASP.Net app from VS 2003 to VS 2005 as a starting point. The app uses Crystal Reports and binds using ADO.Net to a strongly typed dataset (XSD). I had to change some of Crystal Code to work with the newer version of Crystal. Now, when I run the page, the report generates, but none of the fields fill in. I have seen lots of people having the same problem with no real solutions out there. I decided to create a fresh project that does the same thing to remove the conversation from VS 2003 to 2005 as a possible cause of the problem. So my sample program has a button that runs a query, fills the dataset and assigns it to the report. The report displays the headers only. The code is below. I have no idea what to try next.
DataSet1 ds = new DataSet1();
SqlConnection conn =
new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from mytable", conn);
da.Fill(ds);
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("crystalreport.rpt"));
rep.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rep;
CrystalReportViewer1.RefreshReport();
I also created the DataSet1.XSD based on the same MYTABLE table. I get no errors or any indication anything is wrong except that the fields in the report don't populate.
It would take some debugging to know for sure why it's not working for you. Have you looked at the resulting dataset in a debugging session, and seen if it fills correctly?
Here's a good example of a method to work from.
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=SERVERNAME;initial catalog=DATABASENAME;user id=USERNAME;password=PASSWORD;";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select * from mytable";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "mytable");
cnn.Close();
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();