A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for January, 2008

Facing Problem in Enterprise Library-Caching Application Block+WCSF

Posted by kiranpatils on January 31, 2008

Yesterday i have wasted[or invested] my whole day in solving the error…hoohhh..

What i want to do?

I want to use Caching Application Block with WCSF. means when user clicks on submit i have to Cache that page using CAB of MEL. it seems simple but i am facing problem in implementing it.

Problem I was facing

When i calls CacheManager _cacheManager = CacheFactory.GetCacheManager();

it gives me error. I have pasted stack trace here.

Stack Trace is as under:
Could not load file or assembly Microsoft.Practices.EnterpriseLibrary.Common, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0×80131040)
System.TypeInitializationException was unhandled by user code
Message=”The type initializer for ‘Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory’ threw an exception.”
Source=”Microsoft.Practices.EnterpriseLibrary.Caching”
TypeName=”Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory”
StackTrace:
at Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager()
at Consensus.Net.Framework.Common.Caching.Cache.SetCache(String key, Object value) in C:\Latest Poc [Working Folder]\Consensus\Source\Consensus.Net.Framework\Consensus.Net.Framework\Caching\Cache.cs:line 38
at Consensus.Net.Web.Customer.CustomerController.cachepage(Booker booker) in C:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\Customer\CustomerController.cs:line 69
at Consensus.Net.Web.Customer.Views.DefaultViewPresenter.CachePage() in C:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\Customer\Views\DefaultViewPresenter.cs:line 64
at Customer_Default.btnSubmit_Click(Object sender, EventArgs e) in c:\Latest Poc [Working Folder]\Consensus\UI\Consensus.Net.Web\WebSites\DevelopmentWebsite\Customer\Default.aspx.cs:line 138
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

I have searched on google and blog also…But i am unable to find it out. and no help on codeplex also.. i have invested almost one day for it and i don’t want that you people also waste for the same problem

So here’s the solution:

Solution may look so simple but it is working fine and taken much of my time so its most precious for me.
Just add Microsoft.Practices.EnterpriseLibrary.Common.dll(i have it at “C:\Program Files\Microsoft Enterprise Library 3.1 – May 2007\Bin”) Version: 3.1.0.0 to GAC[if you don't know how to add it refer below step or Add it..].

Adding An Assembly to GAC
  1. Click the Assembly Cache node of the console tree. Alternately, you can click the Manage the Assembly Cache link in the pane on the right.
  2. Click the View List of Assemblies in the Assembly Cache link in the pane on the right.Alternately, you can right-click the Assembly Cache node, point to View on the shortcut menu, and select Assemblies.

    The tool displays all assemblies in the Global Assembly Cache in the pane on the right. The tool also displays all native image versions of assemblies in the cache. Native images are versions of assemblies that have been pre-compiled to native code using the Native Image Generator (Ngen.exe).

  3. To delete an assembly from the cache, right-click the assembly name in the pane on the right and choose Delete from the shortcut menu.
  4. To add an assembly to the cache, right-click the Assembly Cache node and choose Add from the shortcut menu. The tool displays the Add an Assembly dialog box. Navigate to the assembly to add.

That’s it .

Happy Caching!!!.

-Kiran Patil

Posted in Enterprise Library | Tagged: , , | 6 Comments »

Cannot Create Database Diagram with SQL Server 2005

Posted by kiranpatils on January 26, 2008

Cannot Create Database Diagram with SQL Server 2005

Today one of my associate has faced one problem: He wants to create Database Diagram in SQL SERVER Management Studio. But he is getting the error like shown as below.

TITLE: Microsoft SQL Server Management Studio

——————————

Database diagram support objects cannot 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 objects.

——————————

BUTTONS:

OK

He asked me to find the solution and I found it. So I am putting it here. So you don’t have to struggle for it.

SOLUTION:

  1. Just copy below SP and copy it to Management studio

EXEC sp_dbcmptlevel ‘<Dbse name>’, ‘90′;

go

ALTER AUTHORIZATION ON DATABASE:: <Dbse name>TO<USER Name>

go

use [<Dbse name>]

go

EXECUTE AS USER = N‘dbo’ REVERT

Go

  1. Now just change <Dbse name> to your Database name for which you are facing problem and <USER Name> with your username of SQL.
  2. Now Try it!!! And Enjoy

Happy Database Diagramming

-Kiran

Posted in SQL SERVER 2005 | Tagged: | 4 Comments »

Converting Hexadecimal Value to Int or VB6 Hexadecimal value to C# Int

Posted by kiranpatils on January 16, 2008

Somewhat busy from last few days and can’t able to write something new here…

Today i have faced new problem i want to convert a hexadecimal value [which i have stored in string and got from VB 6.0] to Int..But i have faced so many problems as under:

1. “Could not find any recognizable digits”.

stack trace:

——————————————————————————————————–

System.FormatException was unhandled
Message=”Could not find any recognizable digits.”
Source=”mscorlib”
StackTrace:
at System.ParseNumbers.StringToInt(String s, Int32 radix, Int32 flags, Int32* currPos)
at System.Convert.ToUInt32(String value, Int32 fromBase)
at HextoInt.Program.HexToInt(String hexString) in F:\Consensus\Appns My\Testharness\HextoInt\Program.cs:line 27
at HextoInt.Program.Main(String[] args) in F:\Consensus\Appns My\Testharness\HextoInt\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

——————————————————————————————————–

Root Cause:

string Hexvalue = “&H69″; //My Hex value is creating problem Here.

Solution

I have copied this string ["&H69"] from VB 6 Output. But when you need to pass a hex value in C#. you have to keep following thing in Mind.

1. It Must starts with 0[zero]x means for my problem solution is here:

string Hexvalue = “&H69″; //ERROR PRONE CODE

string Hexvalue = “0×69″; //NO ERROR HERE

i got help from: http://www.thescripts.com/forum/thread261083.html

2. “Input string was not in a correct format.”

stack trace:

——————————————————————————————————–

System.FormatException was unhandled
Message=”Input string was not in a correct format.”
Source=”mscorlib”
StackTrace:
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s, NumberStyles style)
at HextoInt.Program.HexToInt(String hexString) in F:\Consensus\Appns My\Testharness\HextoInt\Program.cs:line 26
at HextoInt.Program.Main(String[] args) in F:\Consensus\Appns My\Testharness\HextoInt\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
——————————————————————————————————–

Root Cause:

private static int HexToInt(string hexString)
{
return int.Parse(hexString, NumberStyles.HexNumber); // ERROR PRONE CODE
}

Solution

I have created one function for converting Hexa to Int. But it is throwing error.

Frankly speaking, I don’t know why it is not working but i tried other one and now its working..so i am providing you a working one here.

private static int HexToInt(string hexString)
{
int iHex1 = (int)System.Convert.ToUInt32(hexString, 16);
return iHex1;
}

//The above dude is working fine.

3. How to Convert Hexadecimal to Int???

I have tried so many codes,my applications and blogs and all that things which i usually do for Killing the problem. I have found this thing from so many spaces and i am putting it here for centralization purpose. and making your task easy one.

for converting Hexadecimal to Int or Vice versa use functions:

—————————————————————————————————–

1. for Hexadecimal to integer conversion

private static int HexToInt(string hexString)
{
int iHex1 = (int)System.Convert.ToUInt32(hexString, 16);
return iHex1;
}

2. for integer to Hexadecimal conversion

public static string IntToHex(int number)
{
return String.Format(“{0:x}”, number);
}

and ya don’t forget to Import System.Globalization namespace

—————————————————————————————————–

I Got Help from : http://mark.michaelis.net/Blog/HexadecimalConversionsInCNET.aspx

[OPTIONAL] And at last i am pasting my TestHarness Console application here:


using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
namespace HextoInt
{
class Program
{

static void Main(string[] args)
{

string Hexvalue = “0×69″;//”0×100000″;//”&H69″;
//Console.Write(“{0:X}”, Hexvalue);//To Print any/String value in Hexa decimal
Console.WriteLine(“HEX [which is in string] TO INT:–”+HexToInt(Hexvalue));
Console.WriteLine(“INT TO Hex[Output will be in string]:–” + IntToHex(HexToInt(Hexvalue)));

}
private static int HexToInt(string hexString)
{

int iHex1 = (int)System.Convert.ToUInt32(hexString, 16);
return iHex1;
}
public static string IntToHex(int number)
{
return String.Format(“{0:x}”, number);
}

}
}


Have a Happy Conversion!!!

Posted in .NET | Tagged: , | Leave a Comment »