Friday, December 28, 2007

Alter Database Authorization in SqlServer 2005

"Database diagram support object can not be installed because this database does not have a valid owner. To continue, first use the files page of the Database properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support object "

I have resolved the above issue few days ago by alter database authorization. According to MSDN the Alter Authorization syntaxt is

ALTER AUTHORIZATION
ON [ :: ] entity_name
TO { SCHEMA OWNER | principal_name }

::=
{
Object | Type | XML Schema Collection | Fulltext Catalog | Schema
| Assembly | Role | Message Type | Contract | Service
| Remote Service Binding | Route | Symmetric Key | Endpoint
| Certificate | Database
}


my SQL statement was

ALTER AUTHORIZATION ON Database::databasename TO username;

Hope it will help you. Enjoy!

Thursday, December 27, 2007

Read Resource Value Programmatically By C#

There are two types of resource file in .net framework 2.0. They are

1. Global Resource File and
2. Local Resource File

Global resource file can be read by GetGlobalResourceObject method. This method takes two parameter: resource class and the resource key. The class name associates with the .resx file name that contains global resources. Suppose we want the value of "LoginText" from global resource file, named Resource.resx, then our statement will be like below

GetGlobalResourceObject("Resource", "LoginText");

Local resource file which normally stored in App_LocalResources folder, can be read by GetLocalResourceObject method. GetLocalResourceObject takes a resource name as parameter. so we can get a local resource value by the following way

lblMessage.Text = GetLocalResourceObject("msgInvalidLink").ToString();

Enjoy!

Thursday, December 13, 2007

Abnormally LDF File Grow Problem in SQL Server 2005

Recently I had faced a peculiar problem with my database LDF file. My total database MDF file size was 12 MB but the LDF file size was unexpectedly 21 GB!!! As a result I couldn't take the backup of the LDF file to our web server since our web server had only 1 GB free space. I have solved the problem by the following SQL command

BACKUP LOG databaseName WITH TRUNCATE_ONLY
GO
DBCC SHRINKFILE (N'database_log' , 2)

Note: If you get "file in use" error message from the above command, try changing the permission to single user mode.

The above command shrink my database log file to 2 MB. Its awesome and solve my problem within few seconds. Hope it will help. :)

Happy Programming!!!