Wednesday, 26 March 2014

How to deploy windows service


To install a Windows service

1. On the Start menu or Start Page, open the shortcut menu for Developer Command Prompt, and then choose Run As Administrator.

 
 

2.Navigate to the folder that contains your project's output. Navigate to D:\..\bin\Debug

3.Enter the following command:

installutil.exe program.exe

4.  Provide credentials and password. (domain\username)

5.  If the service installs successfully, installutil.exe will report "The transacted install has completed"

6. Go t to Computer Management and start the service “program”

7. Check the progress from Application log file under Windows Log (If you have written the log to Application)



To uninstall windows service
1.  On the Start menu or Start Page, open the shortcut menu for Developer Command Prompt, and then choose Run As Administrator.
2. Navigate to the folder that contains your project's output. For example, D:\..\bin\Debug
3. Enter the following command:
installutil.exe /u program.exe
4.  If the service uninstalls successfully, installutil.exe will report that your service was successfully removed. ("The uninstall has completed.")


 

Friday, 21 March 2014

A first chance exception of type 'System.NullReferenceException' occurred in program.exe


"A first chance exception of type 'System.NullReferenceException' occurred in program.exe"

The debugger will just exit out of the function only leaving this message and go through the rest of the program? How to break at the point this exception throws?

Go to Debug - > Exception (Ctrl + Altre+E) and click on Find. Select the Exception and tick the Thrown check box.

Thursday, 20 March 2014

There is already an open DataReader associated with this Command which must be closed first....

msg:There is already an open DataReader associated with this Command which must be closed first

 

      <add name="ConnectionString"
      connectionString="Data Source=abc\ABCD;Initial Catalog=XYZZ;Integrated Security=True; MultipleActiveResultSets=true"
      providerName="System.Data.SqlClient" />

 
This happens when you have multiple DataReaders open sametime on the same connection. If you call SqlCommand.ExecuteReader but don't close the SqlDataReader returned before calling it again.(Ex: Within a while loop you call another method which opens a data reader).

Solution is to make MultipleActiveResultSets to true in App.Cofig connection string. This is applicable to SQL 2005 and above.

Wednesday, 19 March 2014

Create a workflow to email the count of an event registration in SharePoint2010


Using MS SharePoint Designer 2010;

 1.       Create a list with columns Title and Event Count – This is to store the no of count incrementing in each registration, I call this as Attendance Limits
 
2.       Create a list with a column Title – This is to store the name list of attendees, I call this as Breakfast

3.       Create a new workflow.
What I do check here is if someone get registered, then check if that user is in the List (Breakfast) title column. Else I set a variable list count to the List I created in point 1. Then push the attendee to in the List I created in Point 2. Then I do the calculation which increment the variable list count by 1 and store it for output variable. Delete the current item value in the List which store the counts and update it same time with new count value.


Then I set it to email to the event organizer. Click on the Email on workflow will allow you to edit the lay out of the Email. Here I take email the name of the user who registered and the latest total of attendees.



4. Publish the workflow, Once you publish the workflow you can see the aspx file has been created for the workflow.


5.Modify aspx file as you want to see it, change the layout wordings, font etc…Also if you want to redirect to a thank you page this can be done here.

6.Grant appropriate user permissions to Lists created otherwise Lists won’t get updated when they get registered and total counts may remain 0.

Tuesday, 18 March 2014

Can’t drop schema because it is being referenced by object…

 
Are you getting the below error when you try to drop schemas? Here is a trick to drop such schema.

 

Run the below query to find out what are the objects associates with the relevant schema and reassign objects to a different schema.

SELECT * FROM sys.objects
WHERE name = 'TEMP102913I'
and schema_id = SCHEMA_ID('sysadm');

Wednesday, 12 March 2014

SSRS : How to call sub report grand total on main report

How to call sub report grand total on main report?

Do you have main report with one or more sub report and need to bring the grand total of each sub report to main report within a group? Here is the trick to do this.
You can maintain the sub report as it is. However you need to define same datasets on the main report passing same parameters that you pass to sub reports. The create another tablix with grand total columns on the main report and call these datasets for grand total.

When you view the report, sub report will bring the data and show the sub total within the search group but grand totals for sub reports will be called from the dataset on the main report separately (not from sub report).


Remember to pass the same parameters that you pass to sub reports.

Tuesday, 11 March 2014

Restore a back up taken from SQL 2000 to SQL 2012?

When trying to restore a backup taken on SQL Server 2000 on a SQL Server 2012 RESTORE DATABASE is terminated?

“The database was backed up on a server running version <Old Version>. That version is incompatible with this server, which is running version <New Version>. Either restore the database on a server that supports the backup, or use a backup that is compatible with this server.”

The problem is that on a SQL Server 2012 instance you cannot restore a SQL Server 2000 backup. Practically on SQL Server 2012 you can restore backups taken on SQL Server 2005 or later version.

In such situation you can follow below steps.

- Restoring the SQL Server 2000 backup on SQL Server 2005 or 2008
- Set compatibility level to 90 (SQL Server 2005) or 100 (SQL Server 2008 / SQL Server 2008 R2)
- Backup the same database and restore it on the SQL Server 2012



SSRS: Use the Select All option in the drop down and how to query data to report according to the selections


I have written most of the bits and pieces which may need to make work with SSRS in my previous posts. Here is another common scenario in reports. You may need to select some options or alternately select all the options to view a report. Let’s see how to handle such scenario.

Below scenario, I allow user to select one or more divisions or option to select “”Select All”.
On the report heading when you view the report you also need to show which divisions you have selected, whether you have selected all divisions or one. (Selected Divisions : ...,..,..,)
You may need to handle it using the expression like below. The trick is use JOIN with “,” like below. Use the parameter label with Join which will separated by commas. So if you select only two divisions it will show on the report like
SELECTED SECTION : CS, ENG

How to show the SELECT ALL on the drop down. For that you need to allow multiple values on parameter properties.
Ok, Let’s see how the selected multiple values will be passed to Stored Procedure and bring report data. A trick to solve that problem is to use a function and pass the parameter values to this function which return and set multiple data ready to query eg; DIVISION IN (‘cs’,’eng’)
In the function below split the drop down multiple values and return to my stored procedure. So I can query the division data according to the drop down selections.