Friday, November 23, 2012

How to install an assembly in the Global Assembly Cache (GAC) in .NET

 What is a Shared Assembly?
A shared assembly is one that is used by multiple applications on the machine. A shared assembly must have a name that is globally unique. The .NET Framework supports these naming requirements through a technique called strong names.
Shared assemblies must have a "strong name" consisting of the name of the assembly, the version, a 64 bit hash of a public key (called a ´token´) and the culture.

To create a strong name for an assembly (that is, to generate a public/private key pair), you'll have to use another utility called sn.exe.

In this article, we will create a Visual C# 2010 class Library component called myGAC. We will also create a key file named mykeys.key. We will sign our component with this key file and place it in
To create a Component we have to create a Class Library project by using Visual Studio .NET.
Step 1 : Open Visual Studio .NET
Create a new Class Library project named myGAC in Visual Studio .NET or in Visual c# 2010.

Here is the code for the component. It just includes one method which returns a string.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace myGac
{
    public class Class1
    {

        public string GetName()
        {
            return "Syed Nisar Bukahri";
        }

    }
}

Step 2 : Generating Cryptographic Key Pair using the tool SN.Exe
Now, we will use the SN tool to generate the cryptographic key pair.


sn -k "C:\[DirectoryToPlaceKey]\[KeyName].key"
Next, create a directory named mykeys in C:\ so that you can easily locate the key and access the key from the visual studio command prompt.
Type the following at the command prompt.

sn -k "C:\mykeys\mykeys.key"
Step 3 : Sign the component with the key
A key is generated, but it is not yet associated with the project's assembly.
 To establish the association, open the AssemblyInfo.cs file in Visual Studio 2010 Solution Explorer.Add the following to the
list of assembly attributes that are included in this file by default when a project is created in Visual Studio .NET or in Visual Studio 2005:
[assembly: AssemblyKeyFile("C:\\mykeys\\mk.key")]

Note:Add this line just below the following line
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright ©  2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
...Add this line here.......
Now recompile/build the project and the assembly will be signed.
The next step is to install the assembly into the Global Assembly Cache.

Step 4 : Host the signed assembly in Global Assembly Cache
Using the Global Assembly Cache tool (Gacutil.exe)
You can use Gacutil.exe to add strong-named assemblies to the global assembly cache and to view the contents of the global assembly cache.
At the command prompt, type the following command:

gacutil ­I <assembly name>
In this command, assembly name is the name of the assembly to install in the global assembly cache.

The following example installs an assembly with the file name myGAC.dll into the global assembly cache.

gacutil -I "C:\[PathToBinDirectoryInVSProject]\myGAC.dll"

After hosting the assembly just go to WINNT\Assembly folder and you will find your assembly listed there.
Or if you are running windows 7 go to this location to locate the Assembly
C:\Windows\Microsoft.NET\assembly\GAC_MSIL
and here you will the folder in which is your signed assmbly
like myGac folder
In this will be another folder with name like
v4.0_1.0.0.0__e20b8219cca7baba
and in this folder will be your assemble stored with name as myGac.dll
Step 5 : Test the assembly
Once you've installed the assembly into the GAC, you can use it from other programs by creating a reference.

Now, we will create a sample client application which uses our shared assembly.

In our sample clientGACTest project, expand the project and then right-click on the References item. Select "Add Reference" from the popup menu, and the Add Reference dialog box is displayed.

To refer an assembly in the GAC, just click on the Browse button and browse to the directory (C:\Windows\Microsoft.NET\assembly\GAC_MSIL\v4.0_1.0.0.0__e20b8219cca7baba) that contains the assembly (myGAC.dll).
Locate the assembly, select it, and click OK.

Click on the myGAC reference in Solution Explorer and then examine the Properties pane. You'll see that the Copy Local property is set to False, Strong Name is true,Aliases is global and that the assembly version is 1.0.0.0
Just create a sample code as listed below :

You can now compile and run the clientGAC program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using myGac;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Class1 c = new Class1();
            string str = c.GetName();
            Console.WriteLine(str);
            Console.Read();
        }
    }
}

And it will display the name "Syed Nisar Bukhari"

This article describes how to generate a strong name for an assembly and to install a .dll file in the Global Assembly Cache.
The Global Assembly Cache (GAC) enables you to share assemblies across numerous applications.
 The GAC is automatically installed with the .NET runtime. Components are stored in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\ or  C:\WINNT\Assembly.





Now time to practice!!!!


Thursday, November 22, 2012

How to Change the password for user sa of SQL Server

How to change the password of user sa of SQL Server

Make a login to SQL Server using windows authentication
Go to Security->Logins->right click on sa->properties->General tab and change the password
as
Password:
Confirm password:


Click on Ok   and you are done!!!!

Connect Sql Sever 2008 remotely

Open SQL Server Management studio

In the server name type the machine name  say HP-HP
 Set authentication to SQL Server authentication
Specify Login and password

Hope it helps....

Exception:Login failed for user 'IIS APPPOOL\ASP.NET v4.0

The fix to this exception is as:
Go to  IIS7->Application Pools -> Advanced Settings
Change the ApplicationPoolIdentity as
In Process Model section change the identity to Localsystem.This will make your application run under NT AUTHORITY\SYSTEM, which is an existing login for the database by default.

AdvancedSettings

Hope it helps.....

Sunday, October 14, 2012

SQL SERVER : Error 3154: The backup set holds a backup of a database other than the existing database


Error 3154: The backup set holds a backup of a database other than the existing database

Here is the fix to this error:


Steps:
1) Use WITH REPLACE while using the RESTORE command
2) Delete the older database which is conflicting and restore again using RESTORE command.
RESTORE DATABASE Inventory
FROM DISK = 'C:\BackupInventory.bak'WITH REPLACE
You are actually  trying to restore the database on another existing active database.

Enjoy..this is the efficient fix

Saturday, October 6, 2012

A potentially dangerous Request.Path value was detected from the client (:)

Sometimes you get the following exception when usually opening a page in web browser
A potentially dangerous Request.Path value was detected from the client (:)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (:).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).]
   System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +8884233
   System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +59



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1 

Solution:
1.Check the url properly.Find out if there is any invalid character that has been accidently set as a part of the url.In my case when i got this exception,i did enough of google and all that....when  checked the url and i found that "colon :"  was getting appended to the url at the end.
like this http://localhost/myapp/index.aspx:
It is not always the case with colon...somtimes there may be some other unwanted character...This was the case with my problem...
I removed the colon and the problem was fixed......................and closed all the windows from google search :)


OR
These link may also be helpful
http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_server_error_potentially_dangerous.htm

http://stackoverflow.com/questions/5967103/a-potentially-dangerous-request-path-value-was-detected-from-the-client











Wednesday, October 3, 2012

SQL 2008 - "Saving changes is not permitted." error message.. Whenever any change is made to the table in SQL Server 2008,the following message is displayed Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.

The fix to this warning is as:
Open SQL Server Management Studio (SSMS).
On the Tools menu, click Options.
In the navigation pane of the Options window, click Designers.
Select or clear the Prevent saving changes that require the table re-creation check box, and then click OK.

Note If you disable this option, you are not warned when you save the table that the changes that you made have changed the metadata structure of the table. In this case, data loss may occur when you save the table.
Risk of turning off the "Prevent saving changes that require table re-creation" option

Although turning off this option can help you avoid re-creating a table, it can also lead to changes being lost. For example, suppose that you enable the Change Tracking feature in SQL Server 2008 to track changes to the table. When you perform an operation that causes the table to be re-created, you receive the error message that is mentioned in the "Symptoms" section. However, if you turn off this option, the existing change tracking information is deleted when the table is re-created. Therefore, we recommend that you do not work around this problem by turning off the option.

To determine whether the Change Tracking feature is enabled for a table, follow these steps:
In SQL Server Management Studio, locate the table in Object Explorer.
Right-click the table, and then click Properties.
In the Table Properties dialog box, click Change Tracking.
If the value of the Change Tracking item is True, this option is enabled for the table. If the value is False, this option is disabled.

When the Change Tracking feature is enabled, use Transact-SQL statements to change the metadata structure of the table.

Steps to reproduce the problem

In SQL Server Management Studio, create a table that contains a primary key in the Table Designer tool.
Right-click the database that contains this table, and then click Properties.
In the Database Properties dialog box, click Change Tracking.
Set the value of the Change Tracking item to True, and then click OK.
Right-click the table, and then click Properties.
In the Table Properties dialog box, click Change Tracking.
Set the value of the Change Tracking item to True, and then click OK.
On the Tools menu, click Options.
In the Options dialog box, click Designers.
Click to select the Prevent saving changes that require table re-creation check box, and then click OK.
In the Table Designer tool, change the Allow Nulls setting on an existing column.
Try to save the change to the table.
[Source:Microsoft]


Thursday, September 20, 2012

SQL SERVER – FIX : ERROR : Cannot open database requested by the login. The login failed. Login failed for user ‘NT AUTHORITY\NETWORK SERVICE’.


This error occurs when you have configured your application with IIS, and IIS goes to SQL Server and tries to login with credentials that do not have proper permissions. This error can also occur when replication or mirroring is set up.
Here is the solution:
Go to SQL Server >> Security >> Logins and right click on NT AUTHORITY\NETWORK SERVICE and select Properties
In newly opened screen of Login Properties, go to the “User Mapping” tab. Then, on the “User Mapping” tab, select the desired database – especially the database for which this error message is displayed. On the lower screen, check the role db_owner. Click OK.
Hope this solves your issue

Thursday, September 13, 2012

Manually configure IIS webserver for asp.net 4.0

Hi folks if you are getting this error "Manually configure IIS webserver for asp.net 4.0" then do the following





1.Open visual studio command prompt in administrative mode.
2.Then run this command
       C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i

i.e., you have to reach to v4.0.30319 folder first,then run the command aspnet_regiis -i

Here is the screen shot


Hope this solves your problem

How to Install SQL SERVER – 2008 –A Step By Step Installation Guide


How to Install SQL SERVER – 2008 –A Step By Step Installation Guide 

SQL SERVER 2008 Release Candidate 0 has been released for some time and I have got numorous request about how to install SQL Server 2008. I have created this step by step guide Installation Guide. Images are used to explain the process easier.
[Click On Images to See Larger Image]
[Click On Images to See Larger Image]