This is relatively straight forward. You have a SQL Server Reporting Services server set up somewhere with some Reports on it. Now you want to be able to connect to that Reporting Server from a .Net application to be able to dynamically interact with those reports. In my case I want to be able to run a Report and get back a PDF version of the Results.
First things first you need to connect to the Web Service and to do this you need to add a Reference to the Web Service that is exposed by Reporting Server. Select your Project in Visual Studio, Right Click and select Add Web Service.
In later versions of Visual Studio you will find you can only add Service References, but on the Add Service Reference screen if you select Advanced Options you get the option there to add a Web Reference. Note either way of doing this is fine but I just chose the Web Reference because that directly exposes access to the ReportExecutionService class and thats what we need.
Find the URL of the web service you want to use, this can be found by going to your ReportServer and adding the Web Service address onto the root URL. There are two you can use, the ReportService Web Service has a number of Report Mangement methods on it. The ReportExecution Web Service has a number of processing methods on it.You could add Web References to both into your project if you want to as you most likely would need to use both at some point.
http://server/ReportServer/ReportService2010.asmx?wsdl
http://server/ReportServer/ReportExecution2005.asmx?wsdl
Then in your code you can just create the following to be able to interact with the Web Service methods. Set a web service URL so that you can dynamically change which server you are pointing the code at and set some Credentials.
I will put up a seperate post soon with an example of using this web service to run a Report and retrieve a PDF version of the result within your .Net Application.
A blog to store guides and notes and help on coding. Mostly .Net C# SQL ASP.Net and other related technologies. I post on here things that helped me solve coding issues that I hope will be of help to others.
Thursday, 26 April 2012
Thursday, 10 February 2011
SQL Server - Template Script for Looping Throught Table Without Using Cursor
Below is a single SQL Script I put together to use as a template whenever I need to loop through an SQL Table to then perform operations per row on certain data I can do it using this script.
The template is simple to understand it basically uses a temp table to copy into it the data you are interested in and then loop through it. The template then shows how to use the value you get from each row by just printing it to the screen. Of course you can replace that with any other code you want to.
The template is simple to understand it basically uses a temp table to copy into it the data you are interested in and then loop through it. The template then shows how to use the value you get from each row by just printing it to the screen. Of course you can replace that with any other code you want to.
-- Created 08/04/2010 by Matt Harrison
-- Template for Looping through table rows without using a cursor
------------------------------------------------------------------
DECLARE @RowCnt int
DECLARE @MaxRows int
SET @RowCnt = 1
DECLARE @TempTableName Table (rownum int IDENTITY (1, 1) PRIMARY KEY NOT NULL , Value_Name1 nvarchar(10))
-- Populate the TempTable
INSERT INTO @TempTableName (Value_Name1) (SELECT Value_Name1 FROM DatabaseTableName)
SET @MaxRows = (SELECT count(*) FROM @TempTableName)
-- Foreach Row in TempTableName
WHILE @RowCnt <= @MaxRows
BEGIN
DECLARE @Value_Name nvarchar(10)
SET @Value_Name = (SELECT Value_Name1 FROM @TempTableName WHERE rownum = @RowCnt)
PRINT 'Row Value_Name ' + @Value_Name
-- Next Row
SET @RowCnt = @RowCnt + 1
END
Wednesday, 9 February 2011
Reset Service Broker Quene in SQL Server
I find from time to time when using a Service Broker Queue in SQL Server it just stops and messages just sit in the queue. I have found that the script below forces something to get reset that springs the queue back into life. It's ages since I found this script so can't even remember why it works, but it usually does.
ALTER MASTER KEY FORCE REGENERATE WITH ENCRYPTION BY PASSWORD = 'Password';
Where "Password" can be set to any suitable password.
ALTER MASTER KEY FORCE REGENERATE WITH ENCRYPTION BY PASSWORD = 'Password';
Where "Password" can be set to any suitable password.
Tuesday, 8 December 2009
Reseed an SQL Table Identity Column
If you get an unexpected error like this...
Violation of PRIMARY KEY constraint 'PK_Name'. Cannot insert duplicate key in object 'Table_Name'.
You look at your table and the primary key and realise that the primary key that was complianing was a indentity column then you think well isn't that a bit odd. The point of an identity column is that you insert new rows in a database and it generates a primarykey value for you, usually a unqiue integer value.
Sometimes though for some mystic unknown reason (one that I can't be bothered to find out the real cause for) the identity value that is created is invalid. So whats the solution?
DBCC CHECKIDENT
You can use this SQL command to check what the current status of an identity column on a table is. If you run the below command, it will tell you the current identify value, i.e. the next value that would be generated as a unquire identity value, and it will tell you the current column value, ie. the current highest unqiue identity value used in your database.
Now if it returns something like this then you may have a problem.
Checking identity information: current identity value '10', current column value '17'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
If the current column value is higher than the current identity value then the problem may be that you are trying to insert a new row and the identity value being inserted automatically is '10' when the rows have already been created for identity values up to '17'.
To fix this just run this command to reset the identity value.
Then run the previous command again and you should see this result.
Checking identity information: current identity value '17', current column value '17'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Sorted.
Violation of PRIMARY KEY constraint 'PK_Name'. Cannot insert duplicate key in object 'Table_Name'.
You look at your table and the primary key and realise that the primary key that was complianing was a indentity column then you think well isn't that a bit odd. The point of an identity column is that you insert new rows in a database and it generates a primarykey value for you, usually a unqiue integer value.
Sometimes though for some mystic unknown reason (one that I can't be bothered to find out the real cause for) the identity value that is created is invalid. So whats the solution?
DBCC CHECKIDENT
You can use this SQL command to check what the current status of an identity column on a table is. If you run the below command, it will tell you the current identify value, i.e. the next value that would be generated as a unquire identity value, and it will tell you the current column value, ie. the current highest unqiue identity value used in your database.
DBCC CHECKIDENT ("Table Name", NORESEED);
Now if it returns something like this then you may have a problem.
Checking identity information: current identity value '10', current column value '17'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
If the current column value is higher than the current identity value then the problem may be that you are trying to insert a new row and the identity value being inserted automatically is '10' when the rows have already been created for identity values up to '17'.
To fix this just run this command to reset the identity value.
DBCC CHECKIDENT ("Table Name", RESEED);
Then run the previous command again and you should see this result.
Checking identity information: current identity value '17', current column value '17'.
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Sorted.
Tuesday, 19 May 2009
Make ‘Folders View’ the Windows Explorer Default in Windows XP
Here is a link to a very handy blog post on how to make folders view in the explorer bar, in windows explorer default to folders view, instead of that silly blue common tasks bar.
http://www.daleisphere.com/make-folders-view-the-windows-explorer-default-in-windows-xp/
Great!
http://www.daleisphere.com/make-folders-view-the-windows-explorer-default-in-windows-xp/
Great!
Thursday, 7 May 2009
How to create your own Code Signing Certificates
This has been a real pain for me recently. At work we had previously got code signing certificates from a certificate authority called Thawte. But when it came time to renew, they have been totally unhelpful, slow and inept. We have spent a month dealing with them trying to get a renewed certificated with no joy, so they can now go shove a banana because we are going to sort out our own certificates.
There is a great step by step guide in this forum discussion on channel9 that will help you set up your own code signing certificate.
http://channel9.msdn.com/forums/TechOff/13583-Generating-my-own-Software-Publishing-Certificate/
It's a fiddly process but worth it if all you need is a certificate to sign your code for use within your own network.
There is a great step by step guide in this forum discussion on channel9 that will help you set up your own code signing certificate.
http://channel9.msdn.com/forums/TechOff/13583-Generating-my-own-Software-Publishing-Certificate/
It's a fiddly process but worth it if all you need is a certificate to sign your code for use within your own network.
Wednesday, 29 April 2009
Using SyntaxHighlighter to display code snippets
Today I found a very handy javascript to display code snippets in web pages, and it can be adapted to work in Blogs as well.
The SyntaxHighlighter is very clever, and can display a lot of different code types, for example C#.
There is a nice blog post by Arun K Viswanathan on how to easily adapt the code to work in Blogger. Check it out.
The SyntaxHighlighter is very clever, and can display a lot of different code types, for example C#.
//Here is some C# Code
public void Method()
{
string test = "display some code in my blog";
test = test.tostring() + "and format it nicely";
}
There is a nice blog post by Arun K Viswanathan on how to easily adapt the code to work in Blogger. Check it out.
Subscribe to:
Posts (Atom)