Monday, December 24, 2012

STATISTICS_NORECOMPUTE


During Index Rebuild, one of the parameters a user can set is Statistics_NoRecompute.
The default value is OFF which means "Automatic statistics updating are enabled"
ON = Out-of-date statistics are not automatically recomputed

Monday, December 6, 2010

Formatting Dates (UK, USA)

CDATE does *NOT* return *any* date format!

CDATE *accepts* a date in the current settings.

FormatDateTime will *format* per the current settings.
Or just converting any date to a string via Response.Write or CSTR( ) will do so.

BUT...But that is *not* necessarily the "Regional Settings" on your machine! It is the settings *of the Web Server* that matter.

And to change that, you use
Session.LCID = &H0409 ' for USA
Session.LCID = &H0809 ' for U.K.
To see other LCIDs (and there are dozens!), do this:
(1) Google em!

How to register a C# or VB.Net DLL

Regasm.exe is an Assembly Registration tool used to read the metadata within an assembly. It also adds the necessary entries to the registry allowing a COM client (VB6 applications, or Microsoft VBA, eg. Access, Excel, etc) to create .NET Framework classes. Once a class is registered using Regasm.exe, a COM client can use it as a COM component.

RegAsm.exe file comes with .Net framework installation and can be found in Microsoft.NET framework folder. There are different versions of RegAsm.exe.

1..Net framework 2.0, 3.0, and 3.5 use the same RegAsm.exe which locates in the .Net framework V2.0 folder.
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe
Or
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe
2..Net framework 4.0 uses a new RegAsm.exe which locates in the .Net framework V4.0 folder.
C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
Or
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
RegAsm.exe and DLL mapping
If you receive this error "RegAsm : error RA0000 : Failed to load 'c:\winnt\system32\YourDLLFile.dll' because it is not a valid .NET assembly", you are probably trying to use a .Net framework 2 RegAsm.exe to register a DLL that is created by using .Net framework 4.

.Net Framework RegAsm.exe default installation path Your DLL should be created by
.Net framework 2.0/3.0/3.5 C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe .Net framework 2.0/3.0/3.5
.Net framework 4.0 C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe .Net framework 4.0

So when registering DLL assemblies that are created by .Net framework 4, we must NOT use RegAsm.exe that comes in .Net framework 2.0/3.0/3.5 folder.

How to run RegAsm.exe ?
To execute RegAsm.exe, open a command prompt window, and navigate to the folder where RegAsm.exe is located and run it (otherwise you will get "RegAsm is not recognized as internal or external command, operable program or batch file" error message).

Assume I have already added my DLL to folder C:\WINNT\system32 then I can run the following command:

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /codebase

Note that you don't need to specify C:\WINNT\system32 in the command as it's a system folder. RegAsm.exe will automatically look up SimpleCalc.dll in C:\WINNT\system32 directory.

The /codebase parameter is an optional parameter that adds information about the DLL to the Windows registry which specifies the assembly's path on the disk.

Regasm can also be used to unregister a DLL.

If the DLL you got does not have type library file associated with it, one can be generated by using the Regasm utility and the /tlb option.

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /tlb:SimpleCalc.tlb

Note that, to export a type library from the DLL, you need administrator privileges on the computer, or you will receive this type of error "RegAsm : error RA0000 : An error occurred while saving the exported type library: Access is denied..." because the account under which you run regasm.exe doesn't have rights to write to the folder.

Note that you can create environmental variables for the .Net framework RegAsm.exe to simplify DLL registration.

Friday, May 15, 2009

Write to System Log in Vb.net

To write an entry to System Log, you could do it 2 ways:
  1. Use existing source "Application" in the Event Viewer
  2. Create new source just for your application
BTW: To write logs, all functions are defined under System.Diagnositcs.EventLog namespace. Use: Imports System.Diagnostics.EventLog
To write to existing source, use:
EventLog.WriteEntry("TestApp", "This is Test") -- This will write log under Application with source name as TestApp.
To write to new source, use:
Dim objEventLog As New System.Diagnostics.EventLog()
Dim AppName As String = "Test App"
Dim LogName As String = "My Log"

'Register the App as an Event Source
If Not System.Diagnostics.EventLog.SourceExists(AppName) Then
       System.Diagnostics.EventLog.CreateEventSource(AppName, LogName)
End If
objEventLog.Source = LogName
objEventLog.WriteEntry("This is Test")

HTH.

Sunday, May 10, 2009

SqlServer 2000 Error Logging

To log error in sql log / windows log, just exec the following SP:

….sql code goes here which will cause error.
--To check for error, we use @@error global variable predefined in sql.
set @error = @@error
if @error <> 0
exec sp_altermessage @error ,'with_log', 'true'

To view the error, you can either view either in
  1. windows event viewer
  2. SQL server Mgmt studio , path is : --> Management --> Sql Server Logs
  3. exec master..xp_readerrorlog
To learn more visit
http://www.sqlservercentral.com/articles/Error+Description/65013/

Regards

Saturday, April 25, 2009

MSMQ 4.0 Queue name with .svc

In MSMQ 4.0, if you have a queue name with .svc at the end, you may need to do some additional steps to deliver your messages to receiver over http.

Fix:
  1. Uninstall your WCF components and MSMQ HTTP feature.
  2. Install MSMQ http feature first
  3. Then Install WCF components

This is bug in MSMQ 4.0 and is well explained in the following kb article.

http://support.microsoft.com/default.aspx?scid=kb;EN-US;936502

Basically if you install WCF components before Message Queuing HTTP Support feature (or even together), then the handler mappings are created for the request path whose name contains ".svc" when you enable the WCF feature. The handler mappings are in the Internet Information Services (IIS) default Web site. When you enable the Message Queuing HTTP Support feature, the handler mappings are copied to the Message Queuing virtual directory. This behavior occurs before the Message Queuing HTTP handler mappings are created for the Message Queuing virtual directory. Therefore, any Message Queuing HTTP request to a queue whose name contains ".svc" is sent to the WCF handlers instead of to the Message Queuing HTTP handlers.

Hope this helps.

Saqib

Thursday, September 18, 2008

Resize the textbox of Gridview in EditMode

Protected Sub GridView2_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView2.RowCreated

Dim r As Integer
Dim q As Integer = 0
For q = 0 To GridView2.Rows.Count - 1
For r = 0 to 10
If GridView2.Rows(q).Cells(r).Controls.Count > 0 Then
CType(GridView2.Rows(q).Cells(r).Controls(0), TextBox).Width = Unit.Pixel(52)
End If
Next
Next
End Sub