How to pass dynamic connectionstring with username and password directly in SSRS using C#? - reporting-services

I am using SSRS for reporting purpose in my application.In SSRS i am using Embedded DataSource for fetching data.
I want to pass dynamic connection string in c# code to that datasource so based on connection string parameter it will fetch data assordingly.
Is that possible ?

//Here you can fetch Database Name dynamically and assign to Initial
Catalog for preparing dynamic connection string.
string conStr = #"Data Source=DILIPPC\SQLEXPRESS;Initial Catalog=Student";
// Fetch all datasources
var dataSources = this.reportViewer1.ServerReport.GetDataSources();
List<DataSourceCredentials> credentials = new List<DataSourceCredentials();
foreach (var dataSource in dataSources)
{
DataSourceCredentials credential = new DataSourceCredentials();
credential.Name = dataSource.Name;
credential.UserId = " "; // Wirte username of your connection
credential.Password = " "; // Wirte password of your connection
credentials.Add(credential);
}
this.reportViewer1.ServerReport.SetDataSourceCredentials(credentials);
// Added ConStr parameter and pass this parameter to SSRS report.
ReportParameter rptPar = new ReportParameter("ConStr", conStr);
reportViewer1.ServerReport.SetParameters(rptPar);

Related

Telerik Reporting Error: sqlDataSource does not exist in the current context

I am trying to create a SqlDataSource using Telerik Reporting and am getting errors using the exact code in the documentation attempting to connect to AdventureWorks database:
SqlDataSource sqlDataSource = new SqlDataSource();
sqlDataSource.ProviderName = "System.Data.SqlClient";
sqlDataSource.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";
sqlDataSource.SelectCommand = "SELECT * FROM Production.Product";
The code is placed inside of the body of the class, but it should be placed in a method instead. Use object initializer like this:
SqlDataSource sqlDataSource = new SqlDataSource
{
ProviderName = "System.Data.SqlClient",
ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True",
SelectCommand = "SELECT * FROM Production.Product"
}
or move the initialization code in a separate method.

Load 3D model in Unity using Resource folder and Mysql

I want to load 3D model using Resource folder. I created an sql database to store the address. In this case I stored the file "deer-3ds" in folder "Models" and also save these information in a table named "modeladdress" in sql.
So please help me to correct my code. I know that it's 100% wrong but I dont know how to fix it. Thank you.
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using Mono.Data.Sqlite;
public class addobject : MonoBehaviour {
// Use this for initialization
void Start () {
//GameObject deer=Instantiate(Resources.Load("deer-3d.bak",typeof(GameObject)))as GameObject;
// GameObject instance = Instantiate(Resources.Load("Models/deer-3ds", typeof(GameObject))) as GameObject;
string conn = "URI=file:" + Application.dataPath + "/modeladdress.s3db"; //Path to database.
IDbConnection dbconn;
dbconn = (IDbConnection) new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT ordinary,foldername, filename " + "FROM modeladdress";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read ()) {
int ordinary = reader.GetInt32 (0);
string foldername = reader.GetString (1);
string filename = reader.GetString (2);
string path = foldername + "/" + filename;
//Debug.Log( "value= "+value+" name ="+name+" random ="+ rand);
GameObject instance = Instantiate(Resources.Load(path, typeof(GameObject))) as GameObject;
instance.SetActive (true);
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
// Update is called once per frame
void Update () {
// GameObject instance = Instantiate(Resources.Load("Models/deer-3ds", typeof(GameObject))) as GameObject;
// instance.SetActive (true);
}
}
First of all, you are using SQLite at your database management system, not MySQL. Second, the way you have written your query,
string sqlQuery = "SELECT ordinary,foldername, filename " + "FROM modeladdress";
Will return the ordinary, foldername, and filename for every model. You need to use a WHERE clause to specify precisely which model you want to use. Thus, you need some way to know which model you want to query from the database before you actually execute the query, and in that case, why even query a database? You're going to have to store some unique identifier anyway so a database solves nothing.
Now concerning the actual code you have written, it appears to be correct (i.e. it should be returning what you want). The problem must be that either your table is empty, your values that are returned are incorrect, or that the object is being instantiated in an incorrect location and thus you are thinking it's not working. If you want a more concrete answer you'll have to comment on this answer with the specific problem you are facing (i.e. what specifically is "wrong"?).

How to send a MYSQL resultset object recieved by the servlet to a jsp page?

I have accessed a MYSQL data base and retrieved a result set in the servlet. how do i send the result set to the jsp page and read the different fields from the result set
ex:
Class.forName("com.mysql.jdbc.Driver");
Connection con = DBCon.getConnection(DBType.MYSQL);
PreparedStatement statement = con.prepareStatement(query);
ResultSet data =statement.executeQuery();
request.setAttribute("data", data);
while(data.next()){
System.out.println("ID:" + data.getObject("id")+" Username: " + data.getObject("saltedkey") + " EmailId" + data.getObject("email"));
//this works well in the system console. Now i wd like to send the ResultSet data to jsp.. how do i do that.
}
We should not send the result set object to the JSP. Instead, copy the values into a model, close the result set and connection and set the model into request scope. On the JSP, simply iterate the model.

SSRS Report cache disable using "rs:ClearSession"

I found a way to achieve this that using the query string "rs:ClearSession" have to pass in URL.
Below is my code ASP.NET SSRS Reportviewer integarating page,
rptvw.ProcessingMode = ProcessingMode.Remote;
rptvw.ServerReport.ReportServerUrl = new Uri("http://localhost/reportserver");
rptvw.ServerReport.ReportPath = "/Northwind/NewNorthwind";
ReportParameter[] param = new ReportParameter[1];
param[0] = new ReportParameter("CustomerID", txtparam.Text);
rptvw.ServerReport.SetParameters(param);
rptvw.ServerReport.Refresh();
Question is where should I pass the query string "rs:ClearSession". I tried in above ReportServerUrl and ReportPath but still getting error might be I have done any syntax errors.
Where and how to pass the query string "rs:ClearSession" in URL ?

Connection Manager in Script Component

How will we use Connection Manager in Script component, using OLEDB Provider ? I had tried using Connection Manager with OLEDB Provider and SQL, but failed. what is the correct way to use ?
The syntax is different between a Script Task and a Script Component. Check out this article for more than a couple side-by-side comparisons:
http://msdn.microsoft.com/en-us/library/ms136031.aspx
This is well documented on MSDN, covering both VB and C# type of scripts: http://msdn.microsoft.com/en-us/library/ms136018.aspx
IDTSConnectionManager100 connMgr = this.Connections.ADONetAppStaging ; //this we need to give name in connection manager in script component
SqlConnection myADONETConnection = new SqlConnection();
myADONETConnection = (SqlConnection)(connMgr.AcquireConnection(null));
//Read data from table or view to data table
string query = "Select top 10 * From ##AP_Stagging_Temp_ExportWODuplicates Order by 1,2,3 asc ";
// string query = "Select * From ##AP_Stagging_Temp_For_JLL_ExportWODuplicates order by 1,2,3 asc ";
SqlDataAdapter adapter = new SqlDataAdapter(query, myADONETConnection);
DataTable dtExcelData = new DataTable();
adapter.Fill(dtExcelData);
myADONETConnection.Close();