SQL Server 2005 Management Studio tips

SQL Server 2005 Management Studio tips

February 14, 2009 01:00 by pradeep.mishra

Tip # 1

Problem:  You have too many connections stored in your management studio using IP address. Sometime it is hard to remember the IP address vs server mapping. Or you have scripts to run on various servers in same management studio instance.

Solution: Use SQL Server Connection Registration feature as shown in diagram below and you can organize all your connections in amazing ways. To get this window just go to View -> Registered Servers.

 

 

Tip # 2

Problem: You are trying to get the things done using SQL Server designer because you don’t remember the query syntax. E.g. Adding a new column, insert script etc

Solution: SQL Server Studio has a feature called Template Explorer(Hit CTRl+Alt+T) and you can see readymade queries available for most of the day to day operation. You can even create your own templates. See the diagram below

 

 

 

Hope this will help you in someway.

kick it on DotNetKicks.com

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Zip Compressing ASP.NET Session

Zip Compressing ASP.NET Session

December 1, 2008 14:43 by pradeep.mishra

Here are links to a very good articles on how to compress session so that memory on computer may be saved.

Scott Hanselman posted original entry here

A modified useful version was posted by Al Pascual here

Hope this helps!

 

 


Currently rated 3.5 by 2 people

  • Currently 3.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Running multiple instances of BlogEngine 1.4.5 with single db

Running multiple instances of BlogEngine 1.4.5 with single db

September 13, 2008 17:59 by pradeep.mishra

BlogEngine is a powerful blogging engine and there may be situation in which you would like to use it for multiple websites but one database. One straight solution is to use different table prefix and specify the same in web.config file in appsettings. But I personally don’t like the idea of storing data in two different tables. Given the fact that I am using Asp.Net membership provider, I would like to leverage built in capabilities of membership provider to run two different applications having one single database. So here are the steps involved in running multiple sites with one database, assuming you are using Asp.Net membership provider.

Step1: Configure BlogEngine to use MSSQL and Asp.net membership provider

Users already using MSSQL provider can move to step 2 directly.

If you can access your hosted database remotely you can directly use the aspnet_regsql tool to install all required tables, views, storedprocedure etc. Otherwise use aspnet_regsql tool to create the database locally and then create a script necessary to create the tables, views and stored procedures etc so that the same may be run on the remote hosted site. To see step by step guide see this video

http://nyveldt.com/misc/BE13SQLMembership.html

After you have successfully configured to use MSSQL provider you will be able to see following page.

Step2: Configure BlogEngine to use ApplicationId across the application.

  2.1 Run the MultipleInstanceScript.Sql file. Be sure to check the application name by default it has name ‘BlogEngine’ If you have different application name change the string. The scripts add ApplicationId column to all the tables of BlogEngine.

  2.2 Include DbMultiBlogProvider.cs in your BlogEngine.Core/Providers/ Folder.

Change following settings in web.config file.

Note the extra applicationId attribute of DbMultiBlogProvider. Just check your aspnet_applications table and put the same applicationId value here. Well being lazy I have use ApplicationId instead of application name.

Add following values in Appsettings values

Here IsPrivateBlog attribute is used to identify if anonymous access is allowed or not. Comment explains everything.

That’s it.

If you want to deploy the same application with a different address Just create a new application through visual studio site administration tool and change the applicationId to the newly created applicationId. The script file and class file is attached with the post. In case you have any difficulty in setting up website do let me know.

Hope this helps.

Noesispedia_MultipleInstance_BlogEngine.zip (8.41 kb)

kick it on DotNetKicks.com

Currently rated 3.7 by 3 people

  • Currently 3.666667/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Best way to end user session in asp.net

Best way to end user session in asp.net

September 11, 2008 20:11 by pradeep.mishra

Session is very important state management tool in asp.net. You fill in this object with lots of user specific information when user requests a certain page e.g. Logged in user information like name, emailId etc can be stored after the sucessfull login. However for better performance we must make sure that all the objects are removed from the session when we don't need them. So question arises what's the best way to end user's session in case user logs out. Session object have two method implemented to straight away clear all the objects in session. those are...

 Session.Clear(), Session.RemoveAll()

 Eventually these two methods are serving the same purpose but I am still not able to figure out what's the difference between the two. Seems there is some legecy code left by microsoft developers :-). If you know the difference do let me know.

There is one other method called Abandon() which must be used in case user logs out. Abondon method marks the current session for deletion as soon as user moves to next page. So it is always good to use Session.Abandon() in the logout event. In this way the same session object can not be reused in subsequent request. Let's take an example

   1:   
   2:  Session["UserId"] = "user@noesispedia.com"
   3:  Session.Abandon()
   4:  Response.Write((string)Session["UserId"] )

Session is still accesible in this page however if you try to acess userId in next page it won't be available.

One more point I would like to make here i.e. Session_Start event will be raised in case session is abandoned however if you don't call abandon method and just use Clear() session object won't be destroyed even after logout and Session_Start event will not be fired as session still exists in memory. To summarize use

   1:   
   2:  Session.Clear()
   3:  Session.Abandon() 
   4:  //Redirect to logout page. 

Hope this helps! kick it on DotNetKicks.com

Currently rated 3.7 by 11 people

  • Currently 3.727273/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Dynamic Sorting IEnumerable, List

Dynamic Sorting IEnumerable, List

June 10, 2008 10:29 by pradeep.mishra

Earlier I posted about how to dynamically sort the data using extension method see this http://www.noesispedia.com/post/2008/03/21/Linq-to-Sql-Dynamic-Sorting-without-using-Complete-Dynamic-Linq-Libraries.aspx

In this post I will present a quick solution to sort a list of object based on a property of object.

Suppose you have an object like

   1:   
   2:  public class MockObj
   3:  {
   4:  prop a
   5:  prop b
   6:  prop c
   7:  prop d
   8:  }

 

If you are binding above object with gridview (List) and you want to enable sorting in gridview onsorted event use following code to sort

   1:   
   2:  protected void gv_OnSorting(object sender, GridViewSortEventArgs e)
   3:  {
   4:  if (SortDirection == SortDirection.Ascending)
   5:  ((GridView)sender).DataSource = List.OfType().OrderBy(mo=> mo.GetType().GetProperty(e.SortExpression).GetValue(mo, null));
   6:  else
   7:  ((GridView)sender).DataSource = List.OfType().OrderByDescending(mo=> mo.GetType().GetProperty(e.SortExpression).GetValue(mo, null));
   8:  SortDirection = SortDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
   9:  ((GridView)sender).DataBind();
  10:  }

Note that sortExpression specified in gridview must match with one of the property on the object.

If you don't want to use this quick but dirty solution you can go for extension methods. For more information see following links

 http://mironabramson.com/blog/post/2008/05/Sorting-a-collection-using-sort-expression-string.aspx

http://www.singingeels.com/Articles/Self_Sorting_GridView_with_LINQ_Expression_Trees.aspx 

Thanks to my friend Joseph for giving this solution and saving time in writing case statements :-) 

Hope this helps! 


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5