Tuesday, June 22, 2010

How to: Check whether SQL login exists?

Try some thing like this.

DECLARE @SqlStatement NVARCHAR(4000)
DECLARE @loginName VARCHAR (100)
SELECT @loginName = 'nagasai'
IF NOT EXISTS (SELECT loginname FROM master.dbo.syslogins WHERE NAME = @loginName)
BEGIN
SET @SqlStatement = 'CREATE LOGIN [' + @loginName + '] WITH PASSWORD=N''angel83'',DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]'
EXEC sp_executesql @SqlStatement
END
ELSE
BEGIN
PRINT 'login name ' + @loginName + ' already exists'
END

How to: Create login as sysadmin from T-SQL

Here is the T-SQL code snippet that creates login with sysadmin permissions.

CREATE LOGIN [nagasai] WITH PASSWORD=N'angel83', DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=ON, CHECK_POLICY=ON
GO
EXEC master..sp_addsrvrolemember @loginame = N'nagasai', @rolename = N'sysadmin'

Friday, June 18, 2010

How do I debug a custom action/installer class?

Here is how you can do debug custom action.  You can try using one of the following methods:

  • Add a call in your code to System.Diagnostics.Debugger.Launch. This method opens Just-In-Time debugging and enables you to attach a new debugger to your code.
  • Add a call in your code to MessageBox.Show("Debug Me"). When the message box is shown, use Visual Studio to attach to the MessageBox process. Then add breaks (for Visual C# projects) or stops (for Visual Basic projects) in the code.
  • Set your debugging preferences to start %windir%\Microsoft.net\Framework\version\InstallUtil.exe as an external program on the Debug Page of the Project Designer. The name of the custom action assembly is the command line arguments. When you press F5, you hit your breakpoint. InstallUtil.exe will run your custom actions just as MSI does.

Life was difficult until i find this solution from MSDN.

ASP.NET 4 Breaking Changes

.Net Framework 4.0 comes up with some of major changes as compare to previous versions of .Net Framework 3.5 and 2.0
Following are list of Major Changes in .Net 4.0

  • ControlRenderingCompatabilityVersion Setting in the Web.config File 
  • ClientIDMode Changes 
  • HtmlEncode and UrlEncode Now Encode Single Quotation Marks 
  • ASP.NET Page (.aspx) Parser is Stricter 
  • Browser Definition Files Updated 
  • System.Web.Mobile.dll Removed from Root Web Configuration File 
  • ASP.NET Request Validation 
  • Default Hashing Algorithm Is Now HMACSHA256 
  • Configuration Errors Related to New ASP.NET 4 Root Configuration 
  • ASP.NET 4 Child Applications Fail to Start When Under ASP.NET 2.0 or ASP.NET 3.5 Applications 
  • ASP.NET 4 Web Sites Fail to Start on Computers Where SharePoint Is Installed 
  • The HttpRequest.FilePath Property No Longer Includes PathInfo Values 
  • ASP.NET 2.0 Applications Might Generate HttpException Errors that Reference eurl.axd 
  • Event Handlers Might Not Be Not Raised in a Default Document in IIS 7 or IIS 7.5 Integrated Mode Changes to the ASP.NET Code Access Security (CAS) Implementation 
  • MembershipUser and Other Types in the System.Web.Security Namespace Have Been Moved 
  • Output Caching Changes to Vary * HTTP Header 
  • System.Web.Security Types for Passport are Obsolete 
  • The MenuItem.PopOutImageUrl Property Fails to Render an Image in ASP.NET 4 
  • Menu.StaticPopOutImageUrl and Menu.DynamicPopOutImageUrl Fail to Render Images When Paths Contain Backslashes 

Find detail information of ASP.NET 4 Breaking Changes

Saturday, June 12, 2010

How to : Detecting CD Drive from C#

Recently i was writing a custom application which installs on client machine in that i need to find the client CD driver letter.

Here is an example code snippet for finding driver letter.

System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo drive in drives)
{
  if (drive.DriveType == System.IO.DriveType.CDRom)
  Console.WriteLine(drive.DriveType +"*********" +drive.Name);
}