TipsOnLips.net

Your .net tips and tricks source

About the author

Author Name is someone.
E-mail me Send mail

Recent comments

Authors

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010


Add a database diagram support to a SQL Server 2000 database

When attaching a SQL Server 2000 database to a 2005 SQL Server, the 2005 IDE would not support opening the 2000 database diagrams. But there are two ways to make this happens: 1) In SQL Server 2005 Management Studio do the following:

  1. Right Click on your database, choose properties
  2. Goto the Options Page
  3. In the Dropdown at right labeled "Compatibility Level" choose "SQL Server 2005(90)" [more]

 

2) Or by script:

      EXEC sp_dbcmptlevel 'EnterYourDatabaseNameHere', '90';

 

Also, if you get this error when trying to add a new Diagram:

Error: Database diagram support objects cannot be installed because this database does not have a valid owner

Execute the following script:

EXEC sp_dbcmptlevel 'YourDB, '90';

go

ALTER AUTHORIZATION ON DATABASE::YourDB TO "sa"

go

 

 


Categories: SQL Server
Posted by developer on Friday, August 31, 2007 9:50 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Disable browser Back or Enter keyboard keys using JavaScript

function disableEnter()

    {

        //Disables the BackSpace button.

        if (event.keyCode == 13)

        {

            event.cancelBubble = true;

            event.returnValue = false;

        } [more]

    }

   

    function disableBack()

    {

        //Disables the BackSpace button.

        if (event.keyCode == 8)

        {

            event.cancelBubble = true;

            event.returnValue = false;

        }

    }


Categories: JavaScript
Posted by developer on Thursday, August 30, 2007 11:50 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Get the Identity or Row number value for a SQL server table row

We can retrieve a row number or Identity of a SQL Server table row using the script below:

select identity(int) col INTO #Temp from dbo.table

select * from #Temp

Idenity is retrieved when INTO is used to insert the record into a user or temporary table  

Categories: SQL Server
Posted by developer on Wednesday, August 29, 2007 6:34 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Find an SQL Server database size and table space

To get details about an SQL Server database using the following stored procedure:       

       sp_helpdb 'DatabaseName'

to get help about an SQL Server table, use the following stored procedure:        

       sp_help 'TableName'

 To get details about an SQL Server table and indexes siz, using the following stored procedure:

        sp_spaceused 'TableName'

 ----------------------------------------------------------------------------------------------------

Also, to list all tables that contain a given column name (Source: http://www.cryer.co.uk/brian/sqlserver/sqlsvrhowto.htm)

select sysobjects.name, * from syscolumns, sysobjects

where syscolumns.name like '%MyColumn%'

and sysobjects.id = syscolumns.id

and (sysobjects.xtype='U' or sysobjects.xtype='S')

------------------------------------------------------------------------

To kill all the processes for a specific database, use the following script:

declare @p_DBName sysname

set @p_DBName = 'DatabaseName'

/* Must be run from master */

USE master

/* Check Paramaters */

/* Check for a DB name */

IF (@p_DBName IS NULL)

BEGIN

PRINT 'You must supply a DB Name'

RETURN

END -- DB is NULL

IF (@p_DBName = 'master')

BEGIN

PRINT 'You cannot run this process against the master database!'

RETURN

END -- Master supplied

SET NOCOUNT ON

/* Declare Variables */

DECLARE @v_spid INT,

@v_SQL NVARCHAR(255)

/* Declare the Table Cursor (Identity) */

DECLARE c_Users CURSOR

FAST_FORWARD FOR

SELECT spid

FROM master..sysprocesses (NOLOCK)

WHERE db_name(dbid) = @p_DBName

OPEN c_Users

FETCH NEXT FROM c_Users INTO @v_spid

WHILE (@@fetch_status <> -1)

BEGIN

IF (@@fetch_status <> -2)

BEGIN

SELECT @v_SQL = 'KILL ' + convert(NVARCHAR, @v_spid)

-- PRINT @v_SQL

EXEC (@v_SQL)

END -- -2

FETCH NEXT FROM c_Users INTO @v_spid

END -- While

CLOSE c_Users

DEALLOCATE c_Users


Categories: SQL Server
Posted by developer on Wednesday, August 29, 2007 9:47 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Find a string match starting with a defind word (Basic Regular Expressions)

If we have string HelloWorld and we want the following:

1) Find the a match when the string Hello World starts with the word Hello on a condition the word World is attached to the word Hello.

    ^(?i:Hello) 

Where:

    ^             matches the beginning of a string or line.

    (             Starts a group.

    ?i:           Ignore Case.

    )             Close of group. 

 


Posted by developer on Wednesday, August 29, 2007 6:53 AM
Permalink | Comments (1) | Post RSSRSS comment feed

Drop all triggers from any SQL Server database

To drop all triggers from any database, execute this script:

declare @trigger varchar(1000)

declare @sql nvarchar(1000)

select @trigger = min([name]) from sysobjects where [name] like 'trig_prefix%'

while @trigger is not null [more]

begin

      set @sql = 'drop trigger ' + @trigger

      exec sp_executesql @sql

      select @trigger = min([name]) from sysobjects where [name] like 'trig_mi%' and [Name] > @trigger
end


Categories: SQL Server
Posted by Admin on Monday, August 27, 2007 9:21 AM
Permalink | Comments (7) | Post RSSRSS comment feed

Use HTML link to navigate to the logout page in ASP.NET to avoid postback

When using the LoginStatus control (one of the ASP.NET Membership) to logout,
the page has to postback and that causes an unintentional data retrieval for the page that requested the logout. Then if the page has dynamic controls which have to be populated on every postback, and that causes the dynamic control to be populated and then the logout action happens which a waist of
database and server resources.

The solution is to use a normal link which redirects a page to another page (logout page) that has the following code:              

protected void Page_Load(object sender, EventArgs e)

{

   FormsAuthentication.SetAuthCookie(string.Empty, false);           

   FormsAuthentication.SignOut();           

   Session.Abandon();           

   Response.Redirect("~/LoginDetails/login.aspx");

}


Categories: ASP.NET
Posted by Admin on Wednesday, August 22, 2007 9:35 AM
Permalink | Comments (0) | Post RSSRSS comment feed

Register a Web user control in a Web.config file (ASP.NET)

Register a user control in the Web config file like that: 
<pages>
    <controls>
       <add tagPrefix="user"
        tagName="RandomImage"
        src="~/UserControls/RandomImage.ascx"/>
    </controls>
</pages>

Categories: ASP.NET | Web.config
Posted by developer on Sunday, August 19, 2007 7:32 PM
Permalink | Comments (4) | Post RSSRSS comment feed

Using System.IO.Compression.GZipStream (C#)

Microsoft have included a new library in .NET 2.0 System.IO.Compression.GZipStream to

compress streams, Soup, ViewState.


Categories: C#
Posted by developer on Saturday, August 18, 2007 3:32 PM
Permalink | Comments (1) | Post RSSRSS comment feed

Register a JavaScript file programmatically (ASP.NET)

 To register a js programmatically, use the following:Page.ClientScript.RegisterClientScriptInclude("script1", ResolveUrl("~/include/js/javascriptfile.js"));.

This can live behinde the master page inside the load event.

//Its better to check if the script was registered (Page.ClientScript.IsClientScriptBlockRegistered("script1")). 

Also, you can use another way if you have more script to register which in sequence:

 

      if(!IsPostBack && !Page.ClientScript.IsClientScriptBlockRegistered("URLs"))

        {

         StringBuilder scriptBuilder = new StringBuilder();

         scriptBuilder.Append("<script type='text/javascript' src='");    

         scriptBuilder.Append(ResolveUrl("~/include/js/mmloadmenus2.js"));

         scriptBuilder.Append("'></script>");        

         scriptBuilder.Append("<script type='text/javascript' src='");

         scriptBuilder.Append(ResolveUrl("~/include/js/mm_menu.js"));        

         scriptBuilder.Append("'></script>");

         scriptBuilder.Append("<script language='JavaScript1.2'>mmLoadMenus();</script>");

        Page.ClientScript.RegisterClientScriptBlock(typeof(System.String),"URLs",

        scriptBuilder.ToString());

   }


Categories: ASP.NET | JavaScript
Posted by Admin on Thursday, August 16, 2007 11:05 PM
Permalink | Comments (0) | Post RSSRSS comment feed