|
Hi Gerry. Thanks for your feedback. I have actually come to a decision as to how to handle this. I have started the work on this, but I haven't finished it yet. I will come back and post my solution once it is finished.
Basically my plan is to:
download the report as an rdl (XML file) to local computer in folder under .exe. (This works).
Modify the XML with the _NEW stored procedures. (Working on this)
Save the rdl as OriginalName_New.rdl
Upload OriginalName_New.rdl to server. (This works)
Render OriginalName_New in the report viewer control.
Once the user closes the form, delete OriginalName_New from server (This works)
Delete all of the _New datasets from report server that were used by the report. (This works)
Delete rdl file.
Thanks.
|
|
|
|
|
Sounds great! Glad to hear things are moving along. You now also have a convenient way of "logging" user activity to the server.
|
|
|
|
|
Thanks. Here is the code which handles modifying the Embeded Dataset to point to a different stored procedure. This code requires that you add a web reference to ReportingService2010.
What this code does not show is the following: Earlier in the code we read the SQL from a stored procedure and allow the user to pick some criteria and add a WHERE clause to the query. The new sql is then saved to a new stored procedure which includes the name of the original stored procedure plus _New.
So the goal here is to get the report to use the _New stored procedures. The datasets are embedded and must be repointed to the _New stored procedures.
The following code runs everything. At this time, the user has selected the report that they want to view.
string LocalPath = "";
if (DownloadReport(reportViewer1.ServerReport.ReportPath, out LocalPath))
{
string newPath = "";
if (LoopThroughDatasetsXML(LocalPath, out newPath))
{
CreateReports(cbMOE.Text + "_New", newPath, reportViewer1.ServerReport.ReportPath);
}
}
private bool DownloadReport(string reportPath, out string LocalFolder)
{
bool ret = true;
ReportingService2010.ReportingService2010 rs = new ReportingService2010.ReportingService2010();
rs.Url = "http://" + m_dbSettings.serverName + "/" + m_dbSettings.reportDbName + "/ReportService2010.asmx";
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
byte[] reportDefinition = null;
XmlDocument doc = new XmlDocument();
try
{
reportDefinition = rs.GetItemDefinition(reportPath);
MemoryStream stream = new MemoryStream(reportDefinition);
reportPath = reportPath.Replace(@"/", @"\");
LocalFolder = Directory.GetCurrentDirectory();
LocalFolder = LocalFolder + @"\TrialData\DataAccess\Reports" + reportPath + ".rdl";
string Folder = Path.GetDirectoryName(LocalFolder);
if (!Directory.Exists(Folder))
{
Directory.CreateDirectory(Folder);
}
doc.Load(stream);
doc.Save(LocalFolder);
}
catch (Exception ex)
{
ret = false;
MessageBox.Show("Problem saving reports. " + ex.Message);
throw ex;
}
return ret;
}
private bool LoopThroughDatasetsXML(string reportPath, out string NewFilename)
{
bool ret = true;
NewFilename = "";
List<SP> sp = new List<SP>();
XDocument doc = XDocument.Load(reportPath);
XNamespace ns = doc.Root.Name.Namespace;
try
{
foreach (XElement xe in doc.Descendants(ns + "DataSet"))
{
SP p = new SP();
string commandtext = xe.Element(ns + "Query").Element(ns + "CommandText").Value;
xe.Element(ns + "Query").Element(ns + "CommandText").Value = commandtext + "_New";
XAttribute a = xe.Attribute("Name");
p.SPName = commandtext;
p.DatasetName = a.Value;
sp.Add(p);
}
}
catch (Exception ex)
{
ret = false;
MessageBox.Show("Problem looping through rdl and updating to _New Stored Procedures.\n\n" + ex.Message);
}
if (ret)
{
try
{
if (sp.Count > 0)
{
NewFilename = reportPath.Substring(0, reportPath.Length - 4) + "_New.rdl";
doc.Save(NewFilename);
}
}
catch (Exception ex)
{
ret = false;
MessageBox.Show("Problem saving modified rdl.\n\n" + ex.Message);
}
}
return ret;
}
private void CreateReports(string reportName, string definitionPath, string parentFolder)
{
ReportingService2010.ReportingService2010 rsc = new ReportingService2010.ReportingService2010();
rsc.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsc.Url = "http://" + m_dbSettings.serverName + "/" + m_dbSettings.reportDbName + "/ReportService2010.asmx";
Byte[] definition = null;
ReportingService2010.Warning[] warnings = null;
try
{
FileStream stream = File.OpenRead(definitionPath);
definition = new Byte[stream.Length];
stream.Read(definition, 0, (int)stream.Length);
stream.Close();
}
catch (IOException e)
{
MessageBox.Show(e.Message);
}
try
{
parentFolder = parentFolder.Replace(cbMOE.Text, "");
parentFolder = parentFolder.Substring(0, parentFolder.Length - 1);
reportName = reportName.Replace(".rdl", "");
rsc.CreateCatalogItem("Report", reportName, parentFolder, true, definition, null, out warnings);
}
catch (Exception ex)
{
MessageBox.Show("Problem uploading report. " + ex.Message);
}
}
|
|
|
|
|
Looks good. I would suggest making things more "fine-grained" / modular (once prototyping is complete).
There are opportunities to create: a "dataset parser"; a "report creator"; etc.... that will make reusability and streaming easier / simpler.
You may find some of this should happen on the server and not "off-loaded".
|
|
|
|
|
Thanks Gerry. Yes, I am still tweaking things a bit, but it initially looks good and is working.
Take Care,
David
|
|
|
|
|
|
please give me a valid article link which show me with sample code to show SSRS report in asp.net from report server when SSRS report is deployed to report server. thanks
tbhattacharjee
|
|
|
|
|
|
That's what he asked for - a valid link.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
There are so many out there I suggest you google it and then find one and go with it.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
You're been around here for 13 years and you still don't know the first thing about researching a problem?
|
|
|
|
|
He vants to bite your knowledge. Blahhhh!!!!![^]
This space for rent
|
|
|
|
|
|
He has been told on many occasions, but is just too lazy to do it.
|
|
|
|
|
|
thanks a lot for your link
tbhattacharjee
|
|
|
|
|
Hi All,
I have a windows form application (C#) and the users can login to the application by user name and password, and I need to prevent the same user to login to the system from different machines or only one time login, and if the user is logged in I need to disallow a login with a notification the user is already logged in.
C# Desktop Application Not Web With MS SQL Server Database
Thank you
|
|
|
|
|
One way to do this is to query if there already is a session for that specific user in the system. You can get the information from sys.dm_exec_sessions[^]
Since not every user is allowed to query that view, it's best if you do the check inside a stored procedure upon connecting to the database. If the connection is already found (or actually if there now is two connections) then raise an error from the procedure to inform client application that new connection isn't allowed. Another option is to use Logon Triggers[^]
Depending on the requirements, you can check if the host is different if you need to allow multiple connections from the same host
modified 18-Sep-16 10:31am.
|
|
|
|
|
Hi,
dm_exec_sessions is about sql user authentication, but I need for my application users
In my application database I have a users table with login name and Password
I need to check if the User is open the application and logged in I want prevent it login again
from the same PC or from different PC's
Thanks
|
|
|
|
|
First of all, dm_exec_sessions contains rows for both SQL Server authenticated users and Windows authenticated users. So regardless of the authentication method, a row exists if a connection exists.
What comes to user identification, do you have information about the actual OS user in your user table?
If you do, you could use that info from nt_user_name column and check if that user matches.
|
|
|
|
|
Sorry for coming back so late, but if you still have open questions concerning this, have a look at Restricting logon to SQL Server[^] . Perhaps there would be some usable ideas for you.
|
|
|
|
|
i have TSC TTP-244 Bar code Printer, i am making an application in asp.net to Generate Bar code. Generated Bar Code showing in crystal report. when i am using print command then print label but after one label print, position of text on label shift on top on every time when give print command.
please help me to set print label proper way using this printer.
|
|
|
|
|
The printer settings probably do not match the "label size".
This has nothing to do with C#.
|
|
|
|
|
Member 11166318 wrote: in asp.net
Bear in mind that if you're printing from C#, that happens on the server. If you're expecting the label to appear on the user's printer, then you're going to be disappointed.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Is there an easy way to bind a combobox to populate with the names of the tables in a given dataset? When I search all I am finding are questions and examples of binding to a datatable, not the names of the tables in a dataset.
I was hoping for something similar to when debugging in Visual Studio and you have a watch on a dataset. When you examine the value, you get a dropdown with the table names, and switching will show you the data table in a datagrid view.
I currently clear the items from the combobox, and iterate through the table names adding them to the combobox. When the combobox changes I then set my datamember of my grid view to be dataset[combobox1.SelectedItem.ToString], which works but feels clunky.
My application will be using different typed datasets so I need to be able to change the combobox when the dataset changes.
|
|
|
|