SSRS Report cache disable using "rs:ClearSession" - reporting-services

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 ?

Related

System.Data.OleDb.OleDbException: Invalid path or file name

i have the following code which has been getting me data from flat files. but now all of a sudden i am getting this error
System.Data.OleDb.OleDbException: Invalid path or file name
but the code hasnt changed it worked for months,im not sure what went wrong.
System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
string jsonText;
System.Collections.Generic.List<object> objList = new List<object>();
string strConn = #"Provider=vfpoledb;Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\vt_Flat.dbf;Collating Sequence=machine;";
using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn))
{
System.Data.OleDb.OleDbCommand cmddbf = new System.Data.OleDb.OleDbCommand();
cmddbf.Connection = conn;
conn.Open();
cmddbf.CommandText = "select * from vt_Flat";
var dr = cmddbf.ExecuteReader();
while (dr.Read())
{
objList.Add(new
{
Code = (dr["dp_code"].ToString().Trim()),
});
};
}
var filteredList = objList.Where(obj => ((dynamic)obj).Status == (Request.QueryString["Status"] ?? "") && ((dynamic)obj).DepCode == (Request.QueryString["Code"] ?? ""));
jsonText = json.Serialize(filteredList);
Response.Write(jsonText);
}
is there something wrong with iis permissions?
Aside from the connection having to point to the PATH as already noted by Oleg, in the C# instances of OleDbConnection I have done in the past, the connection string uses
Provider=VFPOLEDB.1
Don't know if it is case/sensitive issue and the ".1" which is also part of the provider string.
Once you have a valid connection to the PATH, then your query can query from any table within the path location. So if you had 2+ files, and needed to join them, you would do so with a standard query / join. In your case, your command text is only "select *" since you changed your original connection that included the table. Change the command text to
"select * from vt_Flat"
OTHER CONSIDERATIONS
Is this being run from some web service project? If so, THAT could be the basis. You as a developer testing are running with your permissions / access. If running as a web server, the WEB-based user account may not have permissions to the folder to process / work with the data.
Check the folder of your production data to ALLOW the web user if so running. If that doesn't work, set permissions on the folder to EVERYBODY (only for testing/confirmation purposes only). See if that is the problem.
Also, from the Provider connection, did you try with it as all upper case VFPOLEDB.1?
Use path instead of file name, e.g.:
Data Source=\\10.0.0.0\wwwroot\apps\assembly\FlatDatabaseDbfs\;

Insert query failing when using a parameter in the associated select statement in SQL Server CE

INSERT INTO voucher (voucher_no, account, party_name, rece_amt, particulars, voucher_date, voucher_type, cuid, cdt)
SELECT voucher_rec_no, #account, #party_name, #rece_amt, #particulars, #voucher_date, #voucher_type, #cuid, #cdt
FROM auto_number
WHERE (auto_no = 1)
Error:
A parameter is not allowed in this location. Ensure that the '#' sign is in a valid location or that parameters are valid at all in this SQL statement.
I've just stumbled upon this whilst trying to fix the same issue. I know it's late but, assuming that you're getting this error when attempting to execute the query via .net, ensure that you are setting the SqlCeParameter.DbType - if this is not specified, you get the exception you listed above.
Example (assume cmd is a SqlCeCommand - all the stuff is in the System.Data.SqlServerCe namespace):
SqlCeParameter param = new SqlCeParameter();
param.ParameterName = "#SomeParameterName";
param.Direction = ParameterDirection.Input;
param.DbType = DbType.String; // this is the important bit to avoid the exception
param.Value = kvp.Value;
cmd.Parameters.Add(param);
Obviously, you'd want to set the DB type to match the type of your parameter.

ADODB Command failing Execute with parameterised SQL query

I have the following JScript code:
var conn = new ActiveXObject ("ADODB.Connection");
conn.Open("Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=blah_blah_blah;User=foo;Password=bar;");
var cmd = new ActiveXObject("ADODB.Command");
cmd.ActiveConnection = conn;
var strSQL = "SELECT id FROM tbl_info WHERE title LIKE :search ORDER BY id";
var search = "test";
try{
cmd.CommandText = strSQL;
var param = cmd.CreateParameter(':search', 200, 1, 100, search);
cmd.Parameters.Append(param);
var rs = cmd.Execute();
}
catch (ex) {
Application.Alert("Error retrieving id information from database.");
}
I've verified (by printing them) that the Connection object is set to be the Command's ActiveConnection, the parameter object has the correct value and the Command object has the correct SQL query as its CommandText. I also inserted an alert statement after each line in the try block to see where the error was occuring - it's fine after cmd.Parameters.Append but the exception gets thrown upon running the Execute statement.
I've tried displaying the actual exception but it's just a generic 'Object error' message.
The query executes fine and returns the correct result set when I just execute the SQL query (without the parameter) straight through the Connection object, but seems to fail when I use a parameterised query with the Command object.
As far as I can see all settings and properties of the Command and Connection objects are correct but for whatever reason it's throwing an exception.
Any help with this would be much appreciated.
With ODBC and ADO, generally speaking, a question mark ? is used as the placeholder for parameters. Parameters are bound in the order they are appended to the Parameters collection to the placeholders in the command. In your example, replace strSQL with:
var strSQL = "SELECT id FROM tbl_info WHERE title LIKE ? ORDER BY id";
You can still name the parameter that you create, but the only purpose it would serve is to be able to reference it by name later (e.g., with cmd.Parameters.Item(":search")).

Trouble with returning results from MySql

Edit: I solved my problem but if you have anything to add please do. Thanks
Note: I did not create the DB it was created by Wordpress hosted on GoDaddy with my site
I have a MySql Database called "wordpress" (for clarity). I want to be able to grab the most recent post from my blog and show it on the landing page for my url.
So my thought is this: connect to the MySql DB, run a query to grab the most recent post, display the post.
I built a class to handle the connection and process the request:
public class DAL
{
private string connectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=[server here]; PORT=[port]; DATABASE=wordpress;
USER=[user name here]; PASSWORD=[password here];";
private OdbcConnection blogConnection;
public DAL()
{
blogConnection = new OdbcConnection(connectionString);
}
public String[] GetRecentPost()
{
string queryString = "SELECT * FROM RecentPost";
String[] recentPost = new String[3];
//ODBC
blogConnection.Open();
OdbcCommand MySqlDB = new OdbcCommand(queryString, blogConnection);
OdbcDataReader reader = MySqlDB.ExecuteReader();
while (reader.NextResult())
{
recentPost[0] = reader.GetString(0);
recentPost[1] = reader.GetString(1);
}
recentPost[2] = reader.HasRows.ToString();
blogConnection.Close();
return recentPost;
}
}
In the queryString above RecentPost is a view I created to simplify the queryString since the query was a bit long.
I already know the view works. I tested it by opening phpMyAdmin from within the GoDaddy Hosting Center and executed the query above and I got the correct result, so I don't think the query/view is wrong.
The code-behind for the landing page:
protected void Page_Load(object sender, EventArgs e)
{
DAL dataAccess = new DAL();
String[] recentPost = dataAccess.GetRecentPost();
Title.Text = recentPost[0];
Post.Text = recentPost[1];
Extra.Text = recentPost[2];
}
So when my page loads the Title and Post texts are empty and Extra.Text is False (which from the DAL is the value from reader.HasRows).
So my guess is that its connecting fine and running the query but maybe on the wrong database? I don't know.
I also tried to debug but then my code throws an error about trying to connect to database.
So my questions are: Do you see anything wrong with the connection string?
If not do you see anything else than would cause a connection to be esablished, a query to run, no exceptions thrown but no results returned?
Any one with experience trying to grab data from thier own wordpress blog?
Thanks for the help - this one has been driving me crazy.
I don't know why my original code wasn't working but I solved my issue. For anyone else having this issue here is how I changed my code (in the GetRecentPost method) and solved my problem:
DataSet ds = new DataSet();
//ODBC
blogConnection.Open();
OdbcDataAdapter MySqlDB = new OdbcDataAdapter(queryString, blogConnection);
MySqlDB.Fill(ds);
return ds.Tables[0];
So instead of an array of strings I used a DataSet. Instead of using the OdbcDataReader I used an OdbcDataAdapter and populated the DataSet with the .Fill() method from OdbcDataAdapter I then returned the first table from the DataSet to my Page_Load method.
Here is my new Page_Load():
DataTable table = dataAccess.GetRecentPost();
if (table.Rows.Count > 0)
{
Title.Text = table.Rows[0]["title"].ToString();
Post.Text = table.Rows[0]["content"].ToString();
}
else
Extra.Text = table.Rows.Count.ToString(); \\if nothing was returned ouput the 0 just to be sure
Hope this helps anyone else with this issue
And thanks for anyone who took the time to look

SqlDependency and table update do not refresh DataContext

I'm having trouble with the implementation of SqlDependency in my project.
I'm using SqlDependency in a WCF Service. WCF Service then holds in memory cache all results from all tables in order to have a huge speed gain. Everything seems to be working fine, except when I'm doing a table row update. If I add or delete a row in my table, DataContext is refreshed and cache is invalidated without problems. But when it comes to a table row update, nothing happens, the cache is not invalidated and when I look in debug mode at the content of DataContext, no changes seems to be there.
Here's the code I'm using (note that I'm using the System.Runtime.Caching object) :
public static List<T> LinqCache<T>(this Table<T> query) where T : class
{
ObjectCache cache = MemoryCache.Default;
string tableName =
query.Context.Mapping.GetTable(typeof(T)).TableName;
List<T> result = cache[tableName] as List<T>;
if (result == null)
{
using (SqlConnection conn =
new SqlConnection(query.Context.Connection.ConnectionString))
{
conn.Open();
SqlCommand cmd = new SqlCommand(
query.Context.GetCommand(query).CommandText, conn);
cmd.Notification = null;
cmd.NotificationAutoEnlist = true;
SqlDependency dependency = new SqlDependency(cmd);
SqlChangeMonitor sqlMonitor =
new SqlChangeMonitor(dependency);
CacheItemPolicy policy = new CacheItemPolicy();
policy.ChangeMonitors.Add(sqlMonitor);
cmd.ExecuteNonQuery();
result = query.ToList();
cache.Set(tableName, result, policy);
}
}
return result;
}
I created an extension method so all I have to do is to query any table like that :
List<MyTable> list = context.MyTable.LinqCache();
My DataContext is opened at the Global.asax Application_OnStart and stored in cache, so I can use it whenever I want in my WCF Service. As well at this moment I'm opening the SqlDependency object with
SqlDependency.Start(
ConfigurationManager.ConnectionStrings[myConnectionString].ConnectionString);
So, is that a limitation of SqlDependency, or I'm doing something wrong/missing something in the process?
I think the problem is that although you do all the work in setting up the command object you then do:
cmd.ExecuteNonQuery();
result = query.ToList();
Which is going to use your SQL Command and throw away the results then LINQ to SQL will generate it's own internally via query.ToList(). Thankfully you can ask LINQ to SQL to execute your own command and translate the results for you so try replacing those two lines with:
results = db.Translate<T>(cmd.ExecuteReader());