<$BlogRSDURL$>

Wednesday, March 31, 2004

.Net: Playing with the GAC 

Finally the time came when had to use the GAC. I was playing around with adding an Explorer Bar while working in .Net. I started with searching in Google and found very excellent work done by Pavel Zolnikov at CodeProject.

This is what I learnt from that article and otherwise while working on this till now.
1. Since this project involves adding/removing things in Explorer, it will not use a new GAC file until restarted. This means lots of explorer closing and starting when working/testing/debugging. He says setting 'Launch folder windows in separate process' setting in Folder Options helps but I have not been able to verify that.
2. Left automatically Visual Studio increments the version number of assembly. Everybody who has opened the AssemblyInfo files would have seen [assembly: AssemblyVersion("1.0.*")], in that file. If left like that, one can have multiple versions of same assembly in the GAC. And happy debugging then!!
3. GAC folder in Windows is a different kind of beast all together. I hate explorer treating certaing things *special*. In case you are wondering it is located at %Windows%\Assembly. Try looking at that folder in the explorer window in Details view and try to add another Column in the details. I could not find a way to do that and let me know if you can! Also look at the same window in Command window and you will be able to see all the folders and files and everything *properly*.
4. .Net Provide gacutil.exe tool for handling additiong removal of files from GAC(of course!). It is located in %Windows%\Microsoft.NET\Framework\v1.1.4322. You can use it from anywhere by adding it to your PATH environment variable. Makes it easier to use.

Well that is it till now regarding this. Wait for a follow-up.

Sunday, March 28, 2004

ADO.Net: Passing parameters to Stored Procedures 

Microsoft can become real irritating sometime. Quite often you come across issues for which there are not solutions but only workarounds. Today I came across something which I have been able to "solve", but I have no idea what was wrong or what is the real issue. Possibely it is something I do not know and my n00b-iness.

I am using largely MS's SqlHelper class from its Data Access Application Block in my project as a layer to access database(If you do not know what it is, Google for Application Blocks. This along with quite a few others, are quite good code samples to do lots of common things in .Net). Apart from that I have written another wrapper function on top of it to handle various calls. Things seem to going pretty much OK.

Wrapper Function
Public Function ExecuteStoredProcedure(ByVal sStoredProcedure As String, ByVal oarParams As SqlParameter(), ByVal type As QUERYTYPE) As Object
Dim oConnection As SqlConnection = New SqlConnection(sConnString)

If type = QUERYTYPE.READER Then
Dim _oReturnVal As SqlDataReader = SqlHelper.ExecuteReader(oConnection, sStoredProcedure, oarParams)
Return _oReturnVal
ElseIf type = QUERYTYPE.SCALAR Then
Dim _oReturnVal As Integer = SqlHelper.ExecuteScalar(oConnection, sStoredProcedure, oarParams)
Return _oReturnVal
ElseIf type = QUERYTYPE.NONQUERY Then
Dim _oReturnVal As Integer = SqlHelper.ExecuteNonQuery(oConnection, sStoredProcedure, oarParams)
Return _oReturnVal
End If
End Function


And all SqlParameter creation is like this.
SQL Parameters
Dim oarParam As SqlParameter() = {New SqlParameter("ParamName",ParamValue)}

But at couple of places I need to call these functions without using the wrapper like this
Direct Calls
Dim oarParam As SqlParameter() = {New SqlParameter("ParamName",ParamValue)}
Dm oConnection As SqlConnection = New SqlConnection(sConnString)
Dim oRoleTable As DataTable = SqlHelper.GetTable(SqlHelper.ExecuteReader(oConnection, CommandType.StoredProcedure, "spGetRolesByFunctionPage", oarParam))


And this fails becuase there is no "@" in front of "ParamName". I have freaking no idea why I need to put "@" here and not anywhere else. It took me pretty long time figuring this out. With this code the statement kept giving me error ParamName is not an argument of Stored Procedure name. Anybody got any freaking idea what is the actual issue?

This page is powered by Blogger. Isn't yours?