Monday, October 12, 2009

How to identify your SQL Server version and edition

Execute following on SQL Server Management studio.

SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

Friday, September 25, 2009

Shrinking the Transaction Log in SQL Server

Shrinking the Transaction Log in SQL Server 2000 / 2005 with DBCC SHRINKFILE

SQL Server 2000

1.

Run this code:

DBCC SHRINKFILE(pubs_log, 2)

NOTE: If the target size is not reached, proceed to the next step.

2.

Run this code if you want to truncate the transaction log and not keep a backup of the transaction log. Truncate_only invalidates your transaction log backup sequence. Take a full backup of your database after you perform backup log with truncate_only:

BACKUP LOG pubs WITH TRUNCATE_ONLY

-or-

Run this code if you want to keep a backup of your transaction log and keep your transaction log backup sequence intact. See SQL Server Books Online topic "BACKUP" for more information:

BACKUP LOG pubs TO pubslogbackup

3.

Run this code:

DBCC SHRINKFILE(pubs_log,2)

The transaction log has now been shrunk to the target size.


Source : http://support.microsoft.com/kb/907511/en-us

SQL Server 2005

  1. Back up the transaction log file to make most of the active virtual log files inactive. Therefore, the inactive virtual log files can be removed in a later step. To do this, run a Transact-SQL statement that is similar to the following Transact-SQL statement.

BACKUP LOG TO DISK = ''

Note In this statement, is a placeholder for the name of the database that you are backing up. In this statement, is a placeholder for the full path of the backup file.
For example, run the following Transact-SQL statement.

BACKUP LOG TestDB TO DISK='C:\TestDB1.bak'

2. Shrink the transaction log file. To do this, run a Transact-SQL statement that is similar to the following Transact-SQL statement.

DBCC SHRINKFILE (, ) WITH NO_INFOMSGS

Note In this statement, is a placeholder for the name of the transaction log file. In this statement, is a placeholder for the target size that you want the transaction log file to be. The target size must be reasonable. For example, you cannot shrink the transaction log file to a size that is less than 2 virtual log files.

3. If the DBCC SHRINKFILE statement does not shrink the transaction log file to the target size, run the BACKUP LOG statement that is mentioned in step 1 to make more of the virtual log files inactive.

4. Run the DBCC SHRINKFILE statement that is mentioned in step 2. After this operation, the transaction log file should be similar to the target size.

Source : http://support.microsoft.com/kb/907511/en-us

Wednesday, June 17, 2009

Running IIS and SQL server in same machine with diferent IP and Same Port

Introduction
In this artical I will explain how to configure IIS and SQL server 2005 in same maching diferent IP and same port.

IIS web site need to start on 
IP : 192.168.10.105  Port : 6666

SQL server need to start on
IP : 192.168.10.28 Port : 6666


Configuring Net work Connection
First we need to assign 2 ip addresses to the NIC. Go to Network connections TCP/IP properties and configure as follows.









Configuring IIS

Go to Web site properties from IIS manager and change settings as follows.




















Then use HttpCfg.exe to configure IIS lisning IPs. In windows 2003 this tool can be found SUPPORT\ folder on installation CD. for more informantion click here

type floowing commands in command prompt. By default httpcfg.exe winn install on "c:\program files\Support tools\"

By default iis will listen for all ips configured to machine. using following command will delete entry for all ip listening. 

httpcfg delete iplisten -i 0.0.0.0

Then add the IP we need to listen using following command

httpcfg set iplisten -i 192.168.10.105

then restart the IIS / Web site from IIS manager.

you can user netstat (netstat -an -p tcp) command to see how the ports are listening.


Configuring SQL Server 2005

Go to Sql Server Configuration Manager. and select correct Sql server instance and double click on TCP/IP appear in right pan.









Then change the settins as follows.












After changes are done re start SQL server.

Again you can user netstat (netstat -an -p tcp) command to see how the ports are listening.

netstat will display as follows.




Monday, January 5, 2009

Model Popup (Ajax Control Toolkit) and ASP.MVC




Model popup is another usefull tool in web applications. Therefore I thought to create easy way to include Model popup in ASP.NET MVC Projects as Stephen Walther (ASP.NET MVC Tip #36 – Create a Popup Calendar Helper) did for Calender Control. 



Added Following Class ModelPopupExtensions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace AjaxControlToolkitMvc
{
public static class ModelPopupExtensions
{
public static string ModelPopup(this AjaxHelper helper,
string BackgroundCssClass,
string CancelControlID,
string DropShadow,
string OkControlID,
string OnOkScript,
string PopupControlID,
string PopupDragHandleControlID,
string dynamicServicePath,
string id,
string elementId)
{
var sb = new StringBuilder();

// Add Microsoft Ajax library
sb.AppendLine(helper.MicrosoftAjaxLibraryInclude());

// Add toolkit scripts
sb.AppendLine(helper.ToolkitInclude
(
"AjaxControlToolkit.ExtenderBase.BaseScripts.js",
"AjaxControlToolkit.Common.Common.js",
"AjaxControlToolkit.DynamicPopulate.DynamicPopulateBehavior.js",
"AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.js",
"AjaxControlToolkit.Compat.Timer.Timer.js",
"AjaxControlToolkit.DropShadow.DropShadowBehavior.js",
"AjaxControlToolkit.Compat.DragDrop.DragDropScripts.js",
"AjaxControlToolkit.DragPanel.FloatingBehavior.js",
"AjaxControlToolkit.ModalPopup.ModalPopupBehavior.js"
));

// Perform $create
string properties = "";
properties = string.Format(@"""BackgroundCssClass"": ""{0}"", ""CancelControlID"": ""{1}"", ""DropShadow"": {2}, ""OkControlID"": ""{3}"", ""OnOkScript"": ""{4}"", ""PopupControlID"": ""{5}"", ""PopupDragHandleControlID"": ""{6}"", ""dynamicServicePath"": ""{7}"", ""id"": ""{8}""",
BackgroundCssClass, CancelControlID, DropShadow, OkControlID, OnOkScript, PopupControlID, PopupDragHandleControlID, dynamicServicePath, id);
properties = "{ " + properties + " }";
sb.AppendLine(helper.Create("AjaxControlToolkit.ModalPopupBehavior", properties, elementId));

return sb.ToString();
}
}
}

Added New overloaded method to the AjaxExtensions class. This method takes an extra parameter for properties.
1
2
3
4
5
6
7
8
9
10
        public static string Create(this AjaxHelper helper, string clientType, string properties, string elementId)
{
var sb = new StringBuilder();
sb.AppendLine("<script type='text/javascript'>");
sb.AppendLine("Sys.Application.add_init(function(){");
sb.AppendFormat(@"$create({0}, {1},null,null,$get('{2}'))", clientType, properties, elementId);
sb.AppendLine("});");
sb.AppendLine("</script>");
return sb.ToString();
}