Skip to main content

Posts

How to delete and create windows service using SC

This post is going to be a really small and simple. In this I will just write down the use of SC utility to delete and create windows services. There are lot of resources on web but I am just posting it to have it for my reference :) as I perform these actions quiet often. How to create .NET windows service :- On local computer Go to Run -> Cmd use SC -  sc create <service name>  binpath= "<exe folder>\<exe name>" e.g. sc create MySampleService binpath= "D:\MySampleServiceProject\MySampleService.exe" point to note: There should not be a space between binPath and '='. Service name should be in double quotes ("). There must be a space between '=' and the services exe path. On Remote Computer Go to Run -> Cmd  use SC -  sc <remoteservername> create <service name>  binpath= "<exe folder>\<exe name>" How to delete.NET windows service :- sc delete <servicename> ...

Detect ASP.NET session timeout

HTTPContext object - Provides access to the entire current context (including the request object). You can use this class to share information between pages. It is created early in the asp.net pipeline. It is also used to map the request to a session. Thus, we can use this object to find out whether the session has expired or not. In my application I am using a master page for the login page and I hope that is what you all will be doing. This is the code which I have used to find redirect the user to another URL if the session has expired. protected override void OnInit(EventArgs e)     {         base.OnInit(e);         if (Context.Session != null)         {             //check whether a new session was generated             if (Session.IsNewSession)             {           ...

Partial Search in sql server

Here I am not going to talk about fulltext search as generally in small applications which not that expensive servers we do not really go for full text indexes. Thus we are going to talk about wild card search. Now a days providing search facility to end user has become quite normal. Users generally will have 'n' fields to search. They can search by providing values for all fields or they may provide values for only one field. There are two solutions to this:- The one i like - I have not put any validation in place which we should as if there is no parameter specified the procedure will fail because of bad syntax as there will be a bad where clause. Thus check if no parameter is spec CREATE PROCEDURE SearchProcedureName         -- Add the parameters for the stored procedure here         @Name VARCHAR(100),         @Id VARCHAR(10),         @error int output AS BEGIN set @error =...

Displaying image is a gridview - ImageField

Can not display images in gridview. Images are not getting displayed in gridview. Quite often I have seen people getting bugged by this problem. This problem arises normally due to wrong image URL. This is because web server was not able to find the image and thus did not return a valid URL. Consider a scenario where in my D: drive I have a folder name Images now if there are few images in it and I just wrote a small program to read the file name and display image using a gridview like this:- Default.aspx - <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"     CodeBehind="Default.aspx.cs" Inherits="GridView_Image._Default" %> <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> </asp:Content> <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderI...

Extension Method C#

Once a type is defined and compiled into a .NET assembly, its definition is, more or less, final. In order to add new members, update members, or remove members we need to recode and recompile the code base into an updated assembly. Or we could use System.Reflection.Emit namespace to reshape a compiled type dynamically. Extension methods allow us to extend the functionality of previously compiled types. Using extension methods, we can add functionality to precompiled types while providing the illusion these methods were there all along. When we create extension methods, the existing precompiled assembly is not literally modified. Rather, the type is extended within the current project. If we package extension methods into a custom .NET *.dll, other applications would need to reference this library to make use of the extensions. To this end, extension methods are really just a way to ‘pretend’ a type has new functionality. The real type is not modified in any way. Why do we need...

Implicitly typed local variables

It is not a new feature anymore, but I realized few of my friends still do not know the benefits and need of it. Thus, I feel it is worth writing. This post may not be helpful for you experts!!! Example to start of with and put few questions         public void ImplicitVars()         {             var i = 0;             var s = "Do I know";             Console.WriteLine("i is of type {0}",i.GetType().FullName);             Console.WriteLine("s is of type {0}",s.GetType().FullName);         } Output i is of type System.Int32 s is of type System.String Now add another line after second Console.WriteLine - i = "Error"; public void ImplicitVars() { var i...

Partition a table present in merge replication and deploy the changes on production

I have been playing with merge application of late, but for production changes and not on a sample project. Let me first share our environment with you. We have a central server and few number of clients. Server and client share same schema. We have used merge replication to replicate the changes. There were some load issues and thus few changes have to be done. I will list down the change, which I am going to talk about today. Partition a table vertically. Transfer data from the existing table into the new table. Make sure that the network usage (replication) will be as less as possible. This is a normal scenario for those who are working on distributed environment. I am sharing this post for all those who will work on such environments in future . Challenges For once it all seems so simple. We can run a data migration script which will transfer data from table A to table B on client and server and we are good. But, the problem is that then the merge replication will try...