Friday, November 21, 2008 #

Manipulating ntext datatype in sql server

We have a table with ntext type of field in sql server database, that actually contains text data.
ntext is used to store the unicode type of data that that takes 2 times storage size in bytes,  is two times the number of characters entered.

Now the scenario is we would like to replace all occurances of a paricular string from the data with another string.

It is very simple to do with Replace command in Sql Server, but the constraint is it only takes varchar/nvarchar type of parameter i.e. we can not run Replace command over ntext, we need to cast/convert ntext into varchar/nvarchar but in that case there are chances of loss of data it can truncate the data while convering ntext into varchar/nvarchar.

UPDATETEXT is the suitable command to achieve this for ntext, it also include other binary type of data type image and text.

Following link is demonstration of UDDATETEXT for ntext datatype:
http://sqlserver2000.databases.aspfaq.com/how-do-i-handle-replace-within-an-ntext-column-in-sql-server.html

Above scenario is for SQL Server 2k only. If we have Sql Server 2k5, we should use varchar(max) and nvarchar(max) for text and ntext.
http://sqltips.wordpress.com/2007/05/28/use-varcharmaxnvarcharmax-instead-of-text-ntext/

 

posted @ Friday, November 21, 2008 9:49 AM | Feedback (0)

Tuesday, November 11, 2008 #

How to use multiple versions of assembly

1. Create 2 shared assemblies with different versions (1.0.0.0 and 2.0.0.0).

2. For assembly 1 include the following reference in project file.
    <Reference Include="TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=508b5c5f7455410a, processorArchitecture=MSIL">
      <HintPath>..\..\TestAssembly\T1\TestAssembly.dll</HintPath>
      <Aliases>Test1</Aliases>
      <Private>False</Private>
    </Reference>

Hint Path Vs Reference Path
As for the "Referece Path" or "Hint Path" in the VS.NET project's setting
files, they're all design-time /dev-time setting used by the IDE. As
described in the IDE's help doc, "Reference Path" are used by the VS.NET
IDE to load all the assembliy references when the Project is loaded into
the VS.NET IDE. And the "Hit Path" is mainly used for building time, when
the IDE will build the project, it'll locate the assemblies which is
required to link through the "Hint Path". Anyway, they're all internally
used by the VS.NET IDE, and is possibly to change in sequential version and
they have nothing to do with the .NET framework CLR's runtime assembly
locating.

For .net framework CLR's runtime assembly locating, it'll follow a well
defined steps, generally, it'll check GAC (if strong-named) first, then,
codebase settting , and private path probing. Here is a MSDN reference
which describing the .NET framework's runtime assembly locating.

3. Form assembly 2 include the following reference in the project file.
    <Reference Include="TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25, processorArchitecture=MSIL">
      <HintPath>..\..\TestAssembly\T2\TestAssembly.dll</HintPath>
      <Aliases>Test2</Aliases>
      <Private>False</Private>
    </Reference>

4. While refering the above assemblies set extern aliases for both the assemblies
      extern alias Test1;
      extern alias Test2;

5. And then we can use Test1 and Test2 as 2 different namespaces

      Test1.TestAssembly.
TestClass t1 = new Test1.TestAssembly.TestClass();
      MessageBox.Show(t1.Add(2, 3).ToString());

      Test2.TestAssembly.TestClass t2 = new Test2.TestAssembly.TestClass();
      MessageBox.Show(t2.Add(2, 3, 4).ToString());

Please note the project referencing both the assemblies will be compiled with the following warnings.

Warning 1 
No way to resolve conflict between "TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25" and "TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=508b5c5f7455410a". Choosing "TestAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=275b13b4e9b16f25" arbitrarily. WindowsApplication1

Warning 2 
The referenced component 'TestAssembly' could not be found.

Above scenario is about when we refer both the assemblies of (same name different versions) in the same code file ..but what if we want to override the functionality of an assembly ver 1.0 with ver 2.0.

put following <runtime> tag under configuration settings in the aplication's config file.

<runtime>
<
assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<
dependentAssembly>
<
assemblyIdentity name="<assemblyName>" publicKeyToken="<publicKeyToken>" culture="<culture>" />
<!--<assemblyIdentity name="TestAssembly" publicKeyToken="5ce1b9763dbb3e84" culture="neutral" />->
<
bindingRedirect oldVersion="<oldVersion>" newVersion="<newVersion>" />
<!--<bindingRedirect oldVersion="1.0.0.0" newVersion="1.1.0.0" />-->
</
dependentAssembly>
</
assemblyBinding>
</
runtime>

posted @ Tuesday, November 11, 2008 9:38 AM | Feedback (0)

Wednesday, November 05, 2008 #

CAMSTUDIO- Record Video

CAMSTUDIO A cool tool that lets you record a video of a section of your screen.  It saves to AVI format, though it also has a feature to convert to a SWF to embed it in a web page.  It’s opensource too. :)

 http://camstudio.org/

 

 

posted @ Wednesday, November 05, 2008 9:35 AM | Feedback (0)

Tuesday, November 04, 2008 #

Docx to Doc conversion

 

posted @ Tuesday, November 04, 2008 10:23 AM | Feedback (0)

Wednesday, September 24, 2008 #

The date in the certificate is invalid or has expired, MSXML error

Following code will display error: The date in the certificate is invalid or has expired. if the SSL cerificate on the server is expired.

set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objHttp.Open "POST", "https://<POSTURL>", false
objHttp.send objRequest

We need to update the SSL certificate to get it work, we can also ignore the above error just by adding following highlightrd lines in the code, in that case communication will no longer be secure.

Const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
set objHttp = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
objHttp
.setOption(2) = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
objHttp.Open "POST", "https://<POSTURL>", false
objHttp.send objRequest

posted @ Wednesday, September 24, 2008 2:10 PM | Feedback (0)

Wednesday, January 23, 2008 #

.Net Videos

Ravi launched the .Net Video site:- http://www.dotnetvideos.net/

posted @ Wednesday, January 23, 2008 8:37 AM | Feedback (1)

Friday, January 04, 2008 #

Using Http PUT method for file upload

The PUT method not as widely used as the POST method is the more efficient way of uploading files to a server. This is because in a POST upload the files need to be combined together into a multipart message and this message has to be decoded at the server. In contrast, the PUT method allows you to simply write the contents of the file to the socket connection that is established with the server.

When using the POST method, all the files are combined together into a single multipart/form-data type object. This MIME message when transferred to the server, has to be decoded by the server side handler. The decoding process may consume significant amounts of memory and CPU cycles for very large files.
The disadvantage with the PUT method is that if you are on a shared hosting enviorenment it may not be available to you. we need to enable the PUT verb for the server extension

Enable PUT on IIS web server:-
=========================
1. Select Virtual Directory  2.=> Properties 3.=> Configuration 4.=> Under Mappigs Tab - select extension (e.g. .aspx)=> add PUT in verb list.

The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request.

Sample Code:-   Following code sample will be used to test the PUT method for Uploading the file, here ASP and VBScript is used in the sample, I'm using XmlHttpRequest object for making HttpRequest and getting the HttpResponse back from the web server.
refernces:- http://upload.thinfile.com/docs/put.php

<%

 

@ language="VBScript" %>
<html>
<
head>
<title>Upload</title>

<script language="VBSCRIPT">dim strURL
Function sendit(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName= mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
dim xmlhttp
set xmlhttp = Createobject("MSXML2.XMLHTTP.3.0")
'strURL = "http://localhost/TEST/" & sfileName
xmlhttp.Open "PUT", strURL, false
xmlhttp.Send sData
show.innerText=
"Status: " & xmlhttp.statusText
show1.innerText=
"Response: " & xmlhttp.responseText
set xmlhttp=Nothing
MsgBox("Done!! File Uploaded Successfully.")
End Function Function Send(sfileName, sType)
sData = getFileBytes(sfileName, sType)
'MsgBox(sData)
sfileName = mid(sfileName, InstrRev(sFileName,"\")+1, len(sfileName))
End FunctionSub showresult()
document.write
"<CENTER>Take A look!<BR/><A href=" & strURL & ">" & URL & "</a></CENTER>"
End SubFunction getFileBytes(flnm, sType)
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
if sType="on" then
objStream.Type = 1 ' adTypeBinary
else
objStream.Type = 2 ' adTypeText
objStream.Charset ="ascii"
end if
objStream.Open
objStream.LoadFromFile flnm
if sType="on" then
getFileBytes = objStream.Read
else
getFileBytes = objStream.ReadText
end ifobjStream.Close
Set objStream = Nothing
End Function</script>
</
head>
<
body><form name="frmUpload" action="" method="post">
<!--WIRE FRAME DESIGN START-->
<table align="center">
<tr>
<td>
<input type="FILE" id="filedata"></td>
</tr>
<tr>
<td>
<input type="Button" value="Submit" onclick="Call sendit(filedata.value, filetype.value)"></td>
</tr>
<tr>
<td>
<input type="checkBox" id="filetype" checked>Type Binary (Uncheck for Type Text)</td>
</tr>
<tr>
<td>
<input type="button" value="SHOW IT" onclick="showresult()"></td>
</tr>
<tr>
<td>
<div id="show" align="center">
</div>
</td>
</tr>
<tr>
<td>
<div id="show1" align="center">
</div>
</td>
</tr>
</table>
</form>
</
body>
</
html>

posted @ Friday, January 04, 2008 11:34 AM | Feedback (4)

Thursday, December 27, 2007 #

Enabling Disabling Button on CheckBox

Scott has written a fantastic validator control to Enabling Disabling the button control on the click of a checkbox, this control is very helpful on a typical disclaimer page.

http://scottonwriting.net/sowblog/posts/13057.aspx

--naren

posted @ Thursday, December 27, 2007 10:06 AM | Feedback (1)

Friday, November 23, 2007 #

Stop Leeching

Many web sites suffer from others directly linking to their image, video and other content. This practice is called often called leeching, hot-linking, or inline-linking and causes wasted bandwidth and increased server load to the victim web site.

Reference:- http://mvolo.com/blogs/serverside/archive/2006/11/10/Stopping-hot_2D00_linking-with-IIS-and-ASP.NET.aspx

Download LeechGuard

posted @ Friday, November 23, 2007 11:51 AM | Feedback (6)

Wednesday, August 29, 2007 #

Web farm with ASP.NET Resources

1. http://www.velocityreviews.com/forums/t121834-building-web-farm-with-aspnet-20.html

2. http://www.c-sharpcorner.com/UploadFile/gopenath/Page107182007032219AM/Page1.aspx

3. http://www.west-wind.com/presentations/loadbalancing/NetworkLoadBalancingWindows2003.asp

4. DFS: http://weblogs.asp.net/owscott/archive/2006/06/07/DFS-for-Webfarm-Usage---Content-Replication-and-Failover.aspx

5. Session State

6. Configure SQL Server to Store ASP.NET Session State

7. Configure ASP.NET for Persistent SQL Server Session State Management 

8. Maintaining Session State on Your Web Farm

9.  Configure SQL Server to Store ASP.NET Session State

10. Analyze ASP.NET Web Application Performance

posted @ Wednesday, August 29, 2007 4:03 PM | Feedback (1)