Saturday, February 12, 2011

Deploy UserControl to Sharepoint



Here are the steps to deploy.
1. Create a WSPBuilder Project in Visual Studio 2008

2. Add folders to the Project which looks similar to the 12 hive. Put your UserControl (.ascx file) in the ControlTemplates of the 12 hive.


Here, TestUC is the UserControl and is added to the ControlTemplates folder I created. I idea behind this is, once this is deployed, as per the folder structure, the TestUC will be deployed to the ControlTemplates folder in the 12 hive.

Also add the elements.xml and the features.xml to the folder (name of the feature, in this case it is DeployUC)

3. Probably the most important of the steps. Open elements.xml and add the UserControl element to the elements.

3. Create a Code folder and add the TestUC.ascx.cs file. We will link the UserControl to its code file using the Inherits property for the UserControl.


4. Open TestUC.ascx and link the Test.ascx.cs file

If you see, DeployUC.Code is the Namespace under DeployUC assembly under which TestUC (the code-behind file for the UserControl) resides. One this feature is deployed, this assembly sits in GAC and can always be found by the TestUC UserControl.

5. Build and deploy the package and this UserControl is now available for use on to any page.

6. Done.

Post your comments and questions if you have any.

Tuesday, February 8, 2011

GUID

Is GUID unique? While each generated GUID is not guaranteed to be unique, the total number of unique keys (2^128 or 3.4×10^38) is so large that the probability of the same number being generated twice is very small.

GUID is a 16 byte (or 128 bits) combination of alphabets and numerics. Once you take it apart, the bits of the GUID break down like this:
  • 60 bits of timestamp,
  • 48 bits of computer identifier,
  • 14 bits of uniquifier, and
  • 6 bits are fixed,

for a total of 128 bits.

More information can be found here.

Tuesday, February 1, 2011

'The database principal owns a schema in the database, and cannot be dropped' error in SQL Server 2005 & 2008

I ran into this situation today. I created a User, made him dbOwner to a database DBX. I no longer needed this User and so tried deleting and got this error.

Drop failed - The database principal owns a schema in the database, and cannot be dropped.

After Googling for sometime, I found that this User called as "Database Principal" has "db_owner" role selected for the schema. This means the Database Principal I want to delete owns the schema.

One solution is to delete the schema and then delete the User. Another Solution was to change the DB_Owner to some another "Database Principal" - to "dbo". I did it and then I was able to delete the user/Database Pricipal successfully.

To change the DB_Owner to some another "Database Principal"; simply Drill Down to your Database in Sql Server Management Studio and further more Drill Down to your_DB_Name > Schemas > db_owner > right click > select properties. You would find the name of the "Database Principal" that you want to delete. Change this to some another "Database Principal"; for Example, to "dbo".

Reference here