Error while loading SSRS Report from SSRS Server - c#

In my mvc project reports are deployed on separate SSRS server and we are loading the SSRS Reports with help of iframe, problem with this is its asking for user name and password while accessing the reports with iframes. To remove the user id ans password prompt I was trying to implement the solution provided on this link
and I changed the code in ReportTemplate.aspx.cs file as below to send the credentials referring this link:
rvSiteMapping.Width = 800;
rvSiteMapping.Height = 600;
rvSiteMapping.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials(#"userid", "password", #"\");
rvSiteMapping.ServerReport.ReportServerCredentials = irsc;
rvSiteMapping.ShowCredentialPrompts = true;
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://12.25.2.24/Reports");
rvSiteMapping.ServerReport.ReportPath = "/report/AssetDetail";
rvSiteMapping.ServerReport.Refresh();
I am getting below error:
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
However its working perfectly fine with below code:
rvSiteMapping.Width = 800;
rvSiteMapping.Height = 600;
rvSiteMapping.ProcessingMode = ProcessingMode.Local;
ReportsDataSet ds = new ReportsDataSet();
var connectionString = ConfigurationManager.ConnectionStrings["LowryATS_Tenant2ConnectionString"].ConnectionString;
SqlConnection conx = new SqlConnection(connectionString);
SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM Assets", conx);
adp.Fill(ds, ds.Assets.TableName);
rvSiteMapping.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + #"AssetReport.rdlc";
rvSiteMapping.LocalReport.DataSources.Add(new ReportDataSource("ReportsDataSet", ds.Tables[0]));
Can anybody please help me with this problem. We are using ssrs 2016 on ssrs server.

Related

Login Failed for User when trying to Open() a SqlConnection in C#

I'm using Sql Server 2017 and Visual Studio 2017. I transferred my database from my PC to my friend's laptop using Generate Scripts. I use the following code in my friend's laptop when trying to connect to said database in the laptop:
using (SqlConnection sqlCon = new SqlConnection(#"Data Source = (local); Initial Catalog = PresentasiDB; Integrated Security = True; Trusted_Connection = True;"))
{
DataTable orderTable = new DataTable();
SqlDataAdapter sqlda;
string insertOrder = "INSERT INTO \"Order\" DEFAULT VALUES";
using (SqlCommand newOrder = new SqlCommand(insertOrder, sqlCon))
{
sqlCon.Open();
newOrder.ExecuteNonQuery();
}
sqlda = new SqlDataAdapter("SELECT TOP 1 * FROM \"Order\" ORDER BY OrderID DESC", sqlCon);
sqlda.Fill(orderTable);
orderID = Convert.ToInt32(orderTable.Rows[0][0]);
}
However, this failed. The failure occurred in the sqlCon.Open() part. I've tried using SQL Server login Authentication and Windows Authentication. Both failed. Someone, please help me.
In the data source you need to specify server name you use to connect to sql server.
As shown in the screen the datasource here is "gaurav.goel
Try your connecting string something like this (for sa login)
string connstr = userid=sa;password=sapassword;server=localhost,1433;database=PresentasiDB;Trusted_Connection=no
To test it did you try entering the server as 'localhost' from management studio?

Failed to open the connection Crystal Reports

I am using Visual Studio 2017 and SQL Server 2017 and the last version of Crystal Reports. I then create a stored procedure in SQL Server and a new report in Visual Studio (C#) using the code to get the connection info from the app.config.
When I try to make the program work in PC client, I have the problem failed to open connection temp - the error is illustrated in the screenshot below.
This is the code for the connection info:
SaleReportCrystal aLL_PUSH_STUDENTS = new SaleReportCrystal();
System.Data.Common.DbConnectionStringBuilder builder = new System.Data.Common.DbConnectionStringBuilder();
builder.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString; ;
string server = builder["Data Source"] as string;
string database = builder["Initial Catalog"] as string;
string UserID = builder["User ID"] as string;
string password1 = builder["Password"] as string;
aLL_PUSH_STUDENTS.SetDatabaseLogon(UserID, password1, server, database);
ReportPrint studentInforamtionRep = new ReportPrint();
studentInforamtionRep.crystalReportViewer1.ReportSource = aLL_PUSH_STUDENTS;
studentInforamtionRep.ShowDialog();
Error:
That error code (17) means: "Server does not exist or access denied."
Hopefully, that should point you in the right direction.

SQL Exception - Network-related or instance specific. SQL Express "It works on my machine" issue

EDIT: It only took a week but I eventually found out the issue, primarily due to pure luck and another error with a more specific fix.
The issue was with the connStr I had made, which for some reason on this machine gave me the error randomly of "System.ArgumentException: Keyword not supported: 'datasource'." during runtime. I then found out a fix for that was to rename the connStr as follows:
connStr = #"server = (server name); Initial Catalog = AutoTestDB; Integrated Security = true";
Should you have this error as I have, try that method of connection. END EDIT
I'm currently working on Automated Testing using Katalon Automated Testing, essentially Selenium for Chrome, and whenever I'm attempting to add the results of the test to our Test Results Database the SQL Exception "A network-related or instance-specific error occurred while establishing a connection to SQL Server. " keeps popping up. TCP/IP is open, as is firewall and remote connections, and I have the SQL-SMS open and running while I run the database with the SQL connection.
However it only happens whenever I'm using a certain machine to access the database which is stored within the machine itself, as it is with every other machine that I use and they all work perfectly fine. The only difference I can think of for this machine is that it uses SQL Express while all the others that I use have the full version of Microsoft SQL-SMS-17.
It's a genuine case of "It works on my machine", except with the caveat that it works on several others and even across different users as we are all working on this automated testing, this machine is the lone exception for this code not working, with the only difference being that it uses SQL Express which should be accounted for with the \\SQLExpress.
C# code with SQL connetions to edit the values into an already made table within the database.
public void testDBAdd(String testName, Boolean pass, String testComment)
{
SqlConnection con;
SqlDataAdapter daAutoTest;
DataSet dsAutoTestDB = new DataSet();
SqlCommandBuilder cmdBAutoTest;
String connStr, sqlAutoTest;
connStr = #"datasource = .\\sqlexpress; Initial Catalog = AutoTestDB; Integrated Security = true";
con = new SqlConnection(connStr);
sqlAutoTest = #"SELECT * FROM TestResults";
daAutoTest = new SqlDataAdapter(sqlAutoTest, connStr);
cmdBAutoTest = new SqlCommandBuilder(daAutoTest);
daAutoTest.FillSchema(dsAutoTestDB, SchemaType.Source, "AutoTest");
daAutoTest.Fill(dsAutoTestDB, "AutoTest");
foreach (DataRow drAutoTest in dsAutoTestDB.Tables["AutoTest"].Rows)
{
if (pass == true && drAutoTest["testName"].ToString() == testName)
{
drAutoTest.BeginEdit();
drAutoTest["testName"] = testName;
drAutoTest["testResult"] = 1;
drAutoTest["testComment"] = testComment;
drAutoTest.EndEdit();
daAutoTest.Update(dsAutoTestDB, "AutoTest");
}
else if (pass == false && drAutoTest["testName"].ToString() == testName)
{
drAutoTest.BeginEdit();
drAutoTest["testName"] = testName;
drAutoTest["testResult"] = 0;
drAutoTest["testComment"] = "Exception: " + testComment;
drAutoTest.EndEdit();
daAutoTest.Update(dsAutoTestDB, "AutoTest");
}
}
}
Code which runs the actual test and gathers if it has passed or failed due to the presence of certain elements, in this case is a certain page displayed when the user logs in and clicks a button.
public void settingTest<TestNumber>()
{
IWebDriver driver = new ChromeDriver();
ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");
driver = new ChromeDriver(options);
String testName = "<Test Number>", testComment = "";
Boolean pass = false;
try
{
settingsLogin(driver);
settingsClick(driver);
Assert.IsTrue(driver.FindElement(ElementLocator).Displayed);
if (driver.FindElement(ElementLocator).Displayed == true)
{
testComment = "Pass";
pass = true;
testDBAdd(testName, pass, testComment);
}
}
catch (Exception ex)
{
testComment = "" + ex.TargetSite + "" + ex.Message;
testDBAdd(testName, pass, testComment);
}
finally
{
driver.Close();
}
}
Not sure, but I think your connection string has an extraneous backslash. You've prefaced the string with a "#" but then used "\\" in the Data Source. You might also try "(localdb)\SQLExpress" as the data source.
It only took a week but I eventually found out the issue, primarily due to pure luck and another error with a more specific fix. The issue was with the connStr I had made, which for some reason on this machine gave me the error randomly of "System.ArgumentException: Keyword not supported: 'datasource'." during runtime. I then found out a fix for that was to rename the connStr as follows:
connStr = #"server = (server name); Initial Catalog = AutoTestDB; Integrated Security = true";
Should you have this error as I have, try that method of connection. And thanks to the users who tried to help in both the comments of the post and in the answers section of this post.

Running project as administrator helps with database but causes system.runtime.interopservices.comexception

I made a project that uses a sqlserverce database for pricelist, emploee info etc, makes offer in PDF and opens new email to send it to client.
First problem was: "The specified table does not exist. [XXXXX]". I found out that if I run project as administrator it helps with connection with database.
But it causes other problem: runing project as administrator gives when Outlook is open (no problem when outlook is closed):
System.Runtime.InteropServices.COMException Retrieving the COM class factory for component with CLSID ..... (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).
when project tries to create new email.
Is there any workaround or way to make both pieces work together? Do you have any leads? I googled a bit but I learned that I have to change registry to avoid second problem. Is there any other way?
This is the code for email:
Outlook.Application objApp = new Outlook.Application();
Outlook.MailItem mail = null;
mail = (Outlook.MailItem)objApp.CreateItem(Outlook.OlItemType.olMailItem);
//The CreateItem method returns an object which has to be typecast to MailItem
//before using it.
mail.Attachments.Add((object)saveFile.FileName, Outlook.OlAttachmentType.olByValue, 1, Type.Missing);
//The parameters are explained below
mail.To = email;
mail.BCC = "someemailshere#something.pl";
mail.Display();
This is code for database connection (happens few times in program):
System.Data.SqlServerCe.SqlCeConnection sqlconnection = new System.Data.SqlServerCe.SqlCeConnection();
System.Data.DataSet DtSet = new System.Data.DataSet();
System.Data.SqlServerCe.SqlCeDataAdapter sqladapter;
string katalog = Application.StartupPath + "\\Bazadanych.sdf"; //Data Source = C:\\Users\\user\\Documents\\Visual Studio 2010\\Projects\\BMGRP\\Oferty BMGRP\\Oferty BMGRP\\bin\\Debug\\BazaDanych.sdf
sqlconnection.ConnectionString = "Data Source = " + katalog + "; Max Database Size=40"; //zmienić na katalog root programu
sqlconnection.Open();
string sql = "SELECT * From Przedstawiciele";
sqladapter = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, sqlconnection);
sqladapter.Fill(DtSet);
comboBox1.DataSource = DtSet.Tables[0];
comboBox1.DisplayMember = "imie";
sqlconnection.Close();
Yes. The program installs in Program files as default.
Additional research shown that it is not possible to do what I wanted to do (run a project as administrator and create email when outlook is on). So only solution was to solve database problem: which is to install application in other folder then program files as #spender suggested. It helped.

Report viewer can't access reports in other database server

I have a web application in asp.net 3.5 published in apps server.I have few SSRS reports deployed in a database server which needed to be accessed from the web app.Both the server are in same network.I am using a report viewer control to show the reports and i am passing the report path dynamically.I am also sending the login credentials from code behind.
The problem is that the report is identified correctly and the proper report parameter are also shown.But when i click the view report button no data appears.I have Sql server 2008 r2 and report viewer version 9.0
Please help me with this. here is a code snippet...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ShowCredentialPrompts = false;
IReportServerCredentials irsc =
new CustomReportCredentials("user", "pass", "domain");
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportServerUrl =
new Uri("http://72.0.170.205:80/ReportServer");
ReportViewer1.ShowParameterPrompts = true;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.Refresh();
ReportViewer1.ServerReport.ReportPath = Request.QueryString["val"];
}
}
Did you check that the reports run ok with the same credentials on http://72.0.170.205:80/Reports ?
Don't know if this can be of any help but here are the differences I see in my implementation :
I don't call ReportViewer1.ServerReport.Refresh();
I call this.RegisterRequiresViewStateEncryption(); ( Had to disable it sometimes )
my reportDisplay application is not the root app. Because of conflicts, back in SSRS2005 I had to use a different name for its session cookie in the web.config. Kept it since then
<sessionState cookieless="UseCookies" cookieName="ASP.NET_SessionId.myCustomName"/>
Protected Sub Load_Report()
Dim Connection As New SqlConnection(Connection_String) 'Server Connection String
Dim Data_Table As New DataTable("DataTable1") *'Create New Data Table in DataSet having same columns as are there in your Datatable*
Dim Query As String
Query = "SELECT Caption,Mobile,Age,City FROM Bond.Book"
Dim Command As New SqlCommand(Query, Connection)
Dim Table_Adapter As New SqlDataAdapter(Command)
Table_Adapter.Fill(Data_Table)
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Book.rdlc")
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Book_DataSet", Data_Table))
ReportViewer1.LocalReport.Refresh()
End Sub
This worked for me. I am able to load report viewer on server and view server data

Categories