I am trying to set a given RDL report to use an embedded data source using my client application. I am using the ReportingService2005 class to interact with SSRS. I need to set the embedded data source to use "Credentials stored securely in the report server" and specify the username and password.
Thank you!
I solved the issue by first publishing the RDL, then calling into the ReportingService2005 GetItemDataSources() method. I then modified that datasource and subsequently called SetItemDataSources() to save the changes into SSRS. Below is a snippet of the code I accomplished this with:
var reportItem = report.TargetFolder + "/" + report.Name;
var dataSources = new DataSource[0];
dataSources = rs.GetItemDataSources(reportItem);
if (dataSources.Any())
{
var dataSource = (DataSourceDefinition)dataSources.First().Item;
dataSource.CredentialRetrieval = CredentialRetrievalEnum.Store;
dataSource.UserName = SsrsUsername;
dataSource.Password = SsrsPassword;
rs.SetItemDataSources(reportItem, dataSources);
}
Related
We have a number of SSRS sites serving reports to various locations. Each of these servers all have custom connections in each and every report (don't ask why, that's a tale too torrid to tell). Our goal is to replace all of these custom data sources with a single shared data source for all reports on each server.
To that end, I have created a C# program that will find each report on each server and point the current custom data sources to a currently existing shared data source. This executes and seems to work fine.
My next goal is to use C# to create the shared data source on each server where none currently exists.
My current dilemma arises here:
private static void CreateSharedDataSource(string user, string password, string connection)
{
DataSourceDefinition source = new DataSourceDefinition();
source.CredentialRetrieval = CredentialRetrievalEnum.Store;
source.ConnectString = connection;
source.Enabled = true;
source.EnabledSpecified = true;
source.Extension = "SQL";
source.ImpersonateUser = false;
source.ImpersonateUserSpecified = false;
source.Prompt = "Enter a user name and password to access the data source:";
source.UserName = user;
source.Password = password;
source.WindowsCredentials = true;
source.OriginalConnectStringExpressionBased = true;
source.UseOriginalConnectString = true;
try
{
service.CreateDataSource("DbDataSource", "/DsFolder", false, source, null);
Console.WriteLine("Data source created successfully");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
The data source is created correctly and the user name and password are updated correctly. The problem is that, when I look at the newly created data source on the server, the Connect string property is empty and, yes, the correct value is being passed to it in the method above. If I plug that value into the shared source on the server and test the connection, it works fine, but I cannot get the C# program to update that value itself.
So, is there something subtle I'm missing? Am I misinterpreting a setting up there? Did I set a value wrong?
Clues appreciated.
I've never tried anything like this but a quick bit of research uncovered this which may be helpful.
https://learn.microsoft.com/en-us/dotnet/api/reportservice2010.datasourcedefinition.originalconnectstringexpressionbased?view=sqlserver-2016
It states
"Expression-based connection strings are not supported in shared data
sources."
Assuming the conneciton string is just a plain text string then I would guess that you could set this to false. This may help preserve the string you pass in.
Alright, found my answer. I had a pre-existing data source that was working so, instead of creating it from scratch, I copied that and only changed the name. That created a data source where the Connect string did persist. Comparing the settings in that with what I was setting revealed:
source.UseOriginalConnectString = false;
whereas, my code was:
source.UseOriginalConnectString = true;
Looking that up in docs and it tells me "If true, the value of the ConnectString property is ignored."
Hmmm... that's intuitive. That's not what that sounds like at all. :)
I have two SQL servers that are being load balanced - AlwaysOn. Only the second one of these servers is supposed to be used for crystal reports. I would like to access the second SQL server using the readOnly flag in the connection string: ApplicationIntent=ReadOnly
In my C# class I am running the crystal reports based on ConnectionInfo()
var myConnectionInfo = new ConnectionInfo();
Tables myTables = reportDocument.Database.Tables;
for (int i = 0; i < myTables.Count; i++)
{
var myTable = myTables[i];
var myTableLogonInfo = myTable.LogOnInfo;
myConnectionInfo.ServerName = 'serverName';
myConnectionInfo.DatabaseName = 'databaseName';
myConnectionInfo.UserID = 'userId';
myConnectionInfo.Password = 'password';
myTableLogonInfo.ConnectionInfo = myConnectionInfo;
myTable.ApplyLogOnInfo(myTableLogonInfo);
}
I haven't found a way to set ApplicationIntent=ReadOnly though. Is this supposed to be done setting myConnectionInfo.Attributes? Unfortunately I haven't found an answer on this yet but unanswered questions:
https://archive.sap.com/discussions/thread/3861287
https://archive.sap.com/discussions/thread/3791155
Unfortunately I did not find a way to use the flag ApplicationIntent=ReadOnly in my posted code snippet.
What I ended up doing:
Instead of using the load balancer IP address (or host name), I am using the IP address of the reporting server directly.
I couldn't find any written documentation whether or not one can use ApplicationIntent=ReadOnly.
Rather than using ConnectionInfo, you could use System.Data.SqlClient.SqlConnectionStringBuilder, which has a settable ApplicationIntent property.
i already went through the following questions.please don't mark as duplicate to my question. https://stackoverflow.com/questions/24432683/crystal-report-is-not-showing-data-after-some-time-in-cr-version-13-0-2000-0
I am facing this issue since last 1 month.My crystal report are working fine development environment (windows-7 32bit,VS2010,Crystal report V.13). I deployed on server (windows server-2012 64bit,core i5 ). Problem is that after some time report getting blank.I search a lot about that and use Dispose(),Close() method,right now I m using the following code.
public static void OpenPdfInBrowser(ReportClass RptReport)
{
string strFilename;
string strFolderName;
string strFile = String.Empty;
string strReportOutputName = String.Empty;
HttpResponse objResponse = HttpContext.Current.Response;
HttpSessionState objSession = HttpContext.Current.Session;
HttpServerUtility objServer = HttpContext.Current.Server;
strFolderName = objServer.MapPath("../ReportOutput");
if (Directory.Exists(strFolderName) == false)
{
Directory.CreateDirectory(strFolderName);
}
//Generate the File Name
strFilename = "";
strFile = objSession.SessionID.ToString() + "_" + DateTime.Now.Ticks.ToString() + ".pdf";
strFilename = strFolderName + "\\" + strFile;
//Set the File Name
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
diskOpts.DiskFileName = strFilename;
//Set the Various Options
ExportOptions exportOpts = new ExportOptions();
exportOpts = RptReport.ExportOptions;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.DestinationOptions = diskOpts;
//Export the Report
RptReport.Export();
//Stream it to the Client
objResponse.ClearContent();
objResponse.ClearHeaders();
strReportOutputName = "Report";
objResponse.ContentType = "application/pdf";
objResponse.AddHeader("Content-Disposition", "inline;filename=Report.pdf");
objResponse.WriteFile(strFilename);
objResponse.Flush();
objResponse.Close();
//Delete the File
System.IO.File.Delete(strFilename);
//Close the Report Object
RptReport.Close();
RptReport.Dispose();
GC.Collect();
}
I am getting the following error in event viewer on deployment server.
The description for Event ID 4353 from source Crystal Reports cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
The keycode assembly, BusinessObjects.Licensing.KeycodeDecoder.dll, cannot be loaded.
Any help will be greatly appreciated. thanks in adnvace.
Copy your asp.net folder to server virtual directory...
Not sure but hope ur problem will resolve. Best Luck.
The issues is looking like, related to the Crystal report installation on the server... If its working fine on the Development Machine and if All the applications required to run the crystal reports are installed on the Deployment server, then please, check.. Application Pool in IIS --> select the Application Pool used for the Web applicaiton --> Advanced Settings-> Enable 32-Applications --> Set this to "True" ..
Please, try and check...
After a long research my problem has been resolved by doing following changes in registry.Actually this issue is related to Print Job Limit which by default 75 I just extend its data size according to my requirement and it work for me.
Go to-->RUN----->Regedit
1-HKEY_LOCAL_MACHINE
2-SOFTWARE
3-SAP BUSINESS OBJECT
4-CRYSTAL REPORT FOR .NET FRAMEWORK(your version no.)
5-REPORT APPLICATION SERVER
6-SERVER
then got to "PrintJobLimit" PROPERTY and change its Data size to whatever you want.
thanks for every one who help me in this
Your approach is correct to use .close and . dispose but the best way to use it is :
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
cryRpt.Close()
cryRpt.Dispose()
End Sub
to open crystal report in PDF you can use http response it will be better in performance :
cryRpt = New ReportDocument
cryRpt.Load(Server.MapPath("Your report path"))
cryRpt.SetDataSource(Your data source)
cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
I'm trying to get a handle on the basics of report viewer control in a ASP.net Webforms project with C#. I'm using Adventure Work reports to get a feel for the basics.
I have a report called SalesOrderNumber under Report Parts on my SQL server
I just want to be able to view it at this point
if (!Page.IsPostBack)
{
// Set the processing mode for the ReportViewer to Remote
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ServerReport serverReport = ReportViewer1.ServerReport;
// Set the report server URL and report path
serverReport.ReportServerUrl =
new Uri("(!removed!");
serverReport.ReportPath =
"/Report Parts/SalesOrderNumber";
// Create the sales order number report parameter
ReportParameter salesOrderNumber = new ReportParameter();
salesOrderNumber.Name = "SalesOrderNumber";
salesOrderNumber.Values.Add("SO50750");
// Set the report parameters for the report
ReportViewer1.ServerReport.SetParameters(
new ReportParameter[] { salesOrderNumber });
I get back
The operation you are attempting on item '/Report Parts/SalesOrderNumber' is not allowed for this item type. (rsWrongItemType)
Assign full path like
"http://ReportServername/ReportFolderName/reportname.rdlc"
Make sure Report servername, ServerPath , ReportMode ,rendermode also
I know it's an old question but still I found - it needs an answer.
As per my view, we should first check report path that we have set.
The SSRS ReportPath setting must specify the full report path.
So if you want to access a report, you should set the below path,
http://YourServerName//ReportServer?/Foldername/ReportName
Note: if you've not created a folder on report server then no need to write FolderName. Directly write ReportName.
I would prefer to see below link if you want to access report server using URL.
Click here
Hope it would be helpful to others who are facing the same issue.
I am trying to deploy Crystal Reports in my MVC application. To get full use of the Crystal Report Viewer, I have to use a webform, which is working fairly well in my dev environment.
The application will be deployed on the user's servers and connect to their personal dbs. This means I do not have the final connection information when designing the report or the application.
I am able to successfully connect using their entries in the web.config file, load a DataTable with the report information, and pass it to the report. However, the report is still asking for the db credentials. The report is set to connect to my db, so it asks for my credentials and will not proceed without them. However, the final report shows the correct info from their db.
I am not sure if I need to change something in the report, or in the code behind. This is how I am setting the report ReportSource now:
protected void Page_Load(object sender, EventArgs e)
{
string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString();
try
{
ReportDocument rd = new ReportDocument();
string strRptPath = Server.MapPath("~/") + "Rpts//" + strReportName;
rd.Load(strRptPath);
SqlParameter[] sqlParams = {};
DataTable testDt = DBHelper.GetTable("rptInvtDuplDesc", sqlParams);
rd.DataSourceConnections.Clear();
rd.SetDataSource(testDt);
CrystalReportViewer1.ReportSource = rd;
}
else
{
Response.Write("<H2>Nothing Found; No Report name found</H2>");
}
}
How do I prevent the report from asking for the original credentials?
EDIT:
If I pass the login to my db like this:
rd.SetDatabaseLogon("username", "password");
I do not get the db login again. The credentials have to be for the db used to create the report, but the displayed results are from the DataTable populated in the method above. If it has the data it needs from the current db, why does it need to connect to the original db?
EDIT2:
I have 2 data sources for this report. One is a table from the db and the other is the result from a stored procedure. I have now learned that is the cause of the extra login.
Have a look at my Blog post here on this.
There are a couple of actions required, but the main one is to create a new TableLogOnInfo instance, and then apply is using ApplyLogOnInfo.
You have to provide credentials for each datasouce in the report.
Ideally, the report will have a single datasource. If this is not possible, you need to provide credentials for each, or data for each.
Something like this works well if you want to provide the data:
rd.Database.Tables[0].SetDataSource(testDt);
rd.Database.Tables[1].SetDataSource(micssys);
Otherwise, something like this will allow the report to access the db directly for each datasource:
rd.SetDatabaseLogon("username","password}");