Showing posts with label aspnet. Show all posts
Showing posts with label aspnet. Show all posts

Tuesday, March 13, 2012

HttpException: The URL-encoded form data is not valid

An httpexception might be poping up in most of the ASP.NET 2.0 applications where there are lot of user controls on your view. Microsoft security update MS11-100 limits the maximum number of form keys, files, and JSON members to 1000 in an HTTP request. Because of this change, ASP.NET applications reject requests that have more than 1000 of these elements.
HTTP clients that make these kinds of requests will be denied, and an error message will appear in the web browser. The error message will usually have an HTTP 500 status code.


Exception information in Windows event log will contain:
Exception type: HttpException
Exception message: The URL-encoded form data is not valid

ASP.NET 2.0
If your application view reaches over 1000 elements, than you will need to configure this value in your web.config file. And following lines need to be added:

<configuration>
<appSettings>
<add key="aspnet:MaxHttpCollectionKeys" value="1000" />
</appSettings>
</configuration>


You should set the value to your need, and it should be any value over 1000. You can give value under 1000 as well if your application works on it.

ASP.NET 1.1
For .NET 1.1 web applications you will have to set a DWORD in registry. Following is the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\1.1.4322.0\MaxHttpCollectionKeys

JSON Limit
Applications that hit this limit for JSON payloads can configure as follows:

<configuration>
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="1000" />
</appSettings>
</configuration>


Reference:
http://support.microsoft.com/kb/2661403

Thursday, November 17, 2011

The 'microsoft.jet.oledb.4.0' provider is not registered on the local machine

On Windows 7 64bit and Windows 2008 64bit system a common error may arise when using Microsoft.jet.oledb.4.0 driver. Applications running in 64bit mode may not be able to access this driver. This is because 64bit version of this driver does not exist.

Solution to this problem is as follows:

1. We use 32bit application, 32bit application will be able to access the ODBC drivers

2. If you are a application developer and need to develop a 64bit application which can connect to csv, excel files, etc using ADO.NET. You should use Microsoft Access Database Engine 2010 which is a small redistributable and available in both 32bit and 64bit versions.


Summary:

Issue:
The 'microsoft.jet.oledb.4.0' provider is not registered on the local machine.
Issue is that Application pool is running in 64bit mode, therefore 32bit Jet drivers not accessible.

Solution:
Microsoft Access Database Engine 2010:
http://www.microsoft.com/download/en/details.aspx?id=13255
Use this provider Microsoft.ACE.OLEDB.12.0 to connect with csv, excel, etc files.

Wednesday, September 21, 2011

How to sort Rows/Data in a DataTable

We can sort binding source, data view and data table default view to sort data in a data table. There are following three methods which can be applied:

Method 1:
bindingSource.DataSource = table
dataGridView.DataSource = bindingSource
bindingSource.Sort = "Column_Name"

Method 2:
Alternatively, you can just use a DataView:

Dim view as DataView = new DataView(table)
view.Sort = "Column_Name"
dataGridView.DataSource = view

Method 3:
or change the DataTable's DefaultView:

table.DefaultView.Sort = "Column_Name"

Column_Name is the name of one or more columns on which a sort is required. So a Column_Name can have following values like: "COUNTRY" or "COUNTRY, POPULATION" or "COUNTRY, POPULATION DESC".

Friday, December 31, 2010

Crystal Reports .NET Error: Load Report Failed

Most of the ASP.NET developers might be familiar with this problem and faced it too. When we Google for it, most of the solutions indicate that the C:\Windows\Temp folder needs permission for NETWORK SERVICE account in Windows Server and ASP NET account in Windows Client.

On my web server i can clearly see temporary files of crystal reports being created when a report is called from ASP.NET page. It is recommended to set a special permission no C:\Windows\Temp folder as follows:

Add permission to List folder and Read
Add permission to Create files, Append files
Add permission to Delete files

This should fix the problem in 80% of the cases. Although there are other scenarios as well which cause this problem. But i have here indicated the one common problem, i hope it works for most of you and save you a day.

Another issue might be in the coding section, if report documents are not properly closed and disposed off, this will trigger the error as well. Whenever a report is called in a web application a copy in C:\Windows\Temp folder is created and than served to the client response.

You should inspect the C:\Windows\Temp folder to see if these temp files are not hanging around, if so that means the report documents are not properly close and disposed after processing. Crystal report document need to be closed by calling the Close() method and than the Dispose() method to clean.

There is a recommendation for this in SAP Crystal reports document, and the code should look similar to the following:
private void Page_Unload(object sender, EventArgs e)
{
if (boReportDocument != null)
{
boReportDocument.Close();
boReportDocument.Dispose();
GC.Collect();
}
}


Reference: Troubleshooting the “Load Report Failed” Error

Friday, November 26, 2010

ASP.NET Change Master page on Run time

As in my earlier post we looked at how we can change Theme of a page on click of a button, this similar principle is applied when we try to change master page on click of a button.

We again have the same question:

Can in Change master page on button click?
How to change master page on click of button?

The answer is again simple after reading the documentation of System.Web.UI.Page.MasterPageFile() property:

Property: Public Overridable Property MasterPageFile() As String
Member of: System.Web.UI.Page
Summary: Gets or sets the file name of the master page.
Exceptions:
System.InvalidOperationException: The System.Web.UI.Page.MasterPageFile
property is set after the System.Web.UI.Page.PreInit event is complete.
System.Web.HttpException: The file specified in does not exist or The page does not have a System.Web.UI.WebControls.Content control as the top level control.


The 'MasterPageFile' property can only be set in or before the 'Page_PreInit' event.

Same work around to change the MasterPageFile on run time on click of a button:

Partial Class Default
Inherits System.Web.UI.Page

Protected Sub btnChange_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnChange.Click
'Cannot change MasterPageFile on Click event
End Sub

Protected Sub Page_PreInit(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.PreInit
'If Page is postback
If Me.IsPostBack = True Then
If Not Request(btnChange.UniqueID) Is Nothing Then
Me.MasterPageFile = "~/NewMasterpage.master"
End If
End If

End Sub

End Class


We have changed the MasterPageFile in 'Page_PreInit' event but on click of a button.

UniqueID of a control gets the unique, hierarchically qualified identifier for the server control. The fully qualified identifier for the server control, this is the ID which is received as key when value is post back.

The output of button is like this:
<input type="submit" name="btnChange" value="Change Theme" id="btnChange" />

Here name is what we call btnChange.UniqueID and id is what we call btnChane.ClientID, in HTML input controls "id" is used for client side validation and other java script things, and "name" attribute is used to identify the field when it is post back to server.

Tuesday, November 23, 2010

ASP.NET Change Page Theme on Run time

A simple question about setting themes in ASP.NET would be of in which event I can set the or change the Theme of my page. Like if i want to give an option for user to select from list of available themes and the site on run time could be changed to a specific theme.

Can in Change theme on button click?
How to change theme on click of button?

The answer was simple after reading the documentation of System.Web.UI.Page.Theme() property:

Property: Public Overridable Property Theme() As String
Member of: System.Web.UI.Page
Summary: Gets or sets the name of the page theme.
Exceptions:
System.InvalidOperationException: An attempt was made to set System.Web.UI.Page.Theme after the System.Web.UI.Page.PreInit event has occurred.
System.ArgumentException: System.Web.UI.Page.Theme is set to an invalid theme name.


The 'Theme' property can only be set in or before the 'Page_PreInit' event.

I have made a work around to change the theme on run time on click of a button:

Partial Class Default
Inherits System.Web.UI.Page

Protected Sub btnChange_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles btnChange.Click
'Cannot change theme on Click event
End Sub

Protected Sub Page_PreInit(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.PreInit
'If Page is postback
If Me.IsPostBack = True Then
If Not Request(btnChange.UniqueID) Is Nothing Then
Me.Page.Theme = "NewTheme"
End If
End If

End Sub

End Class


We have still changed the theme in 'Page_PreInit' event but on click of a button.

UniqueID of a control gets the unique, hierarchically qualified identifier for the server control. The fully qualified identifier for the server control, this is ID which is received as key when value is post back.

The output of button is like this:
<input type="submit" name="btnChange" value="Change Theme" id="btnChange" />

Here name is what we call btnChange.UniqueID and id is what we call btnChane.ClientID, in HTML input controls "id" is used for client side validation and other java script things, and "name" attribute is used to identify the field when it is post back to server.

Friday, November 12, 2010

ASP.NET Circular File Reference

“Circular file references are not allowed” error occurs while building or deploying asp.net website, this can happen due to differnt reasons:

1. When one ASCX control references another which contains a reference back to the first one
2. When an ASCX control references another in a different directory that also contains other controls that reference back to the first one
3. When a ASPX page references ASCX control in a different folder, that also contain other pages that reference this control

There might be other reasons as well, ASP.NET website compiles into different libraries, which reference each other as well, .NET compiler bt default build libraries in batch, means files in one folder are batched together in a single library depending on the dependencies.

In "batch mode," the output of multiple source files is compiled into single assemblies according to the type of file, file dependencies, and other criteria. The result is a target site containing a set of assemblies with the executable code for the original source files.
<system.web>
<compilation debug="true" batch="false">
</compilation>
</system.web>

Here batch="false"tells the ASP.NET compiler to not batch assemblies, and create an assembly for each web form and user control. When it is set to true, then the compiler will batch assemblies.

Circular reference is a by-product of the ASP.NET compiler "batching" assemblies together for performance reasons. By default it will take the web forms and user controls in a folder and compile them into an assembly.

There are several ways to solve this issue, but we recommend moving the referenced pages (e.g. Pages2.aspx.vb and Pages3.aspx.vb) to their own folder. By default, the ASP.NET compiler will create a separate assembly containing these pages and the circular reference will be removed between Assembly A and B.

Wednesday, November 3, 2010

Visual Basic .NET Data Type Summary

The following table shows the Visual Basic data types, their supporting common language runtime types, their nominal storage allocation, and their value ranges.

Visual Basic typeCommon language runtime type structureNominal storage allocationValue rangeSystem.
Data.SqlDbType
Boolean

Boolean

Depends on implementing platformTrue or FalseBit
ByteByte1 byte0 through 255 (unsigned)TinyInt
ByteByteByte arrayArray sizeBinary [8000]
Image [2147483647]
Timestamp [8]
VarBinary [8000]
Char (single character)Char2 bytes0 through 65535 (unsigned)
DateDateTime8 bytes0:00:00 (midnight) on January 1, 0001 through 11:59:59 PM on December 31, 9999DateTime
SmallDateTime
DecimalDecimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9...E+28) † with no decimal point;
0 through +/-7.9228162514264337593543950335 with 28 places to the right of the decimal;
smallest nonzero number is +/-0.0000000000000000000000000001 (+/-1E-28) †
Decimal
Money
SmallMoney
Double (double-precision floating-point)Double8 bytes-1.79769313486231570E+308 through -4.94065645841246544E-324 † for negative values;
4.94065645841246544E-324 through 1.79769313486231570E+308 † for positive values
Float
IntegerInt324 bytes-2,147,483,648 through 2,147,483,647 (signed)Int
Long (long integer)Int648 bytes-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18 †) (signed)BigInt
ObjectObject (class)4 bytes on 32-bit platform
8 bytes on 64-bit platform
Any type can be stored in a variable of type Object
SByteSByte1 byte-128 through 127 (signed)
Short (short integer)Int162 bytes-32,768 through 32,767 (signed)SmallInt
Single (single-precision floating-point)Single4 bytes-3.4028235E+38 through -1.401298E-45 † for negative values;
1.401298E-45 through 3.4028235E+38 † for positive values
Real
String (variable-length)String (class)Depends on implementing platform0 to approximately 2 billion Unicode charactersChar [8000]
Nchar [4000]
Ntext [1073741823]
NVarChar [4000]
Text [2147483647]
VarChar [8000]
UIntegerUInt324 bytes0 through 4,294,967,295 (unsigned)
ULongUInt648 bytes0 through 18,446,744,073,709,551,615 (1.8...E+19 †) (unsigned)
User-Defined (structure)(inherits from ValueType)Depends on implementing platformEach member of the structure has a range determined by its data type and independent of the ranges of the other members
UShortUInt162 bytes0 through 65,535 (unsigned)

† In scientific notation, "E" refers to a power of 10. So 3.56E+2 signifies 3.56 x 102 or 356, and 3.56E-2 signifies 3.56 / 102 or 0.0356.

Tuesday, November 2, 2010

ASP.NET Control ClientID and UniqueID, Server control ID

When ever a Server control is rendered in ASP.NET it has two different identifiers, one is named as ClientID which is the "id" attribute and second is the UniqueID which is the "name" attribute.

UniqueID of a control gets the unique, hierarchically qualified identifier for the server control. The fully qualified identifier for the server control, this is the ID which is received as key when value is post back.

The output of button and a text box is like this:
<input type="submit" name="btnLoad" value="Load" id="btnLoad" />
<input type="text" name="txtName" value="Hello" id="txtName" />

Here "name" is what we call btnLoad.UniqueID and "id" is what we call btnLoad.ClientID, in HTML input controls "id" is used for client side validation and other java script things, and "name" attribute is used to identify the field when it is post back to server.

These ID's are in a hierarchy, parent control id first and then child control id, like as follows:
<asp:Repeater ID="rptrNames" runat="server">
<ItemTemplate>
<asp:textbox runat="server" ID="txtName"></asp:textbox>
</ItemTemplate>
</asp:Repeater>

The output of text box is like this:
<input name="rptrNames$ctl00$txtName" type="text" id="rptrNames_ctl00_txtName" />

<input name="rptrNames$ctl01$txtName" type="text" id="rptrNames_ctl01_txtName" />

and so on.

Here ctl00 and ctl01 is Id representing each item of the repeater, txtName is the id for control and rptrNames is the id of repeater control.
The hierarchy of controls is like this:
-Repeater control (Parent control)
--Repeater item (Child control of repeater and parent control of text box)
---TextBox inside each repeater item (Child control of repeater item)

Therefore the UniqueID of textbox is "rptrNames$ctl01$txtName" and ClientID of texbox is "rptrNames_ctl01_txtName".

Another thing noticeable here is the separator between the parent and child control ID's, in case of UniqueID it is "$" dollar sign and in case of ClientID it is "_" underscore. This are fixed control id separators and can be accessed using the read-only property ClientIDSeparator() As Char and read-only property IdSeparator() As Char.

The property ClientIDSeparator() As Char will return (_) underscore and the property IdSeparator() As Char will return ($).

Friday, February 12, 2010

VS2008 Win Form - Calling Crystal report

Dim objRPT As New rptmatchstats

Dim objfrmRPTViewer As New frmreportviewer

'Note: The form has to be shown first, other wise report parameters are prompted
objfrmRPTViewer.CRPTViewer.Visible = False
objfrmRPTViewer.MdiParent = Me.MdiParent
objfrmRPTViewer.WindowState = FormWindowState.Maximized
objfrmRPTViewer.Show()

objRPT.PrintOptions.PaperSize = CrystalDecisions.[Shared].PaperSize.PaperLetter

oConn.applyLogonInfo(objRPT)

'Set Parameters
oConn.assignParameterValueToReport(objRPT, "@id", 10)

objfrmRPTViewer.CRPTViewer.ReportSource = objRPT

objfrmRPTViewer.CRPTViewer.ParameterFieldInfo.Clear()

objfrmRPTViewer.CRPTViewer.ParameterFieldInfo = objRPT.ParameterFields

objfrmRPTViewer.CRPTViewer.Visible = True

Thursday, May 21, 2009

Regular Expressions

Phone or Fax 999-999-9999
"\d{3}\-\d{3}\-\d{4}"

Phone or Fax (999) 999-9999
"\(\d{3}\) \d{3}\-\d{4}"

Simple Email
(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})

Email blah@blah.com
"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$"

Email blah._blah@blah.com
"^(([\w-]+\.)+[\w-]+|([a-zA-Z0-9]{1}|[\w-]{2,}))+@([-0-9a-zA-Z]+[._])+[a-zA-Z]{2,6}$"

Number 965
"\d\"

Saturday, April 25, 2009

VB.Net - Get Week Number of a date

Public Function GetWeekNumber(ByVal inDate As DateTime) As Integer
Const JAN As Integer = 1
Const DEC As Integer = 12
Const LASTDAYOFDEC As Integer = 31
Const FIRSTDAYOFJAN As Integer = 1
Const THURSDAY As Integer = 4
Dim ThursdayFlag As Boolean = False

' Get the day number since the beginning of the year
Dim DayOfYear As Integer = inDate.DayOfYear

' Get the numeric weekday of the first day of the
' year (using sunday as FirstDay)
Dim StartWeekDayOfYear As Integer = _
DirectCast(New DateTime(inDate.Year, JAN, FIRSTDAYOFJAN).DayOfWeek, Integer)
Dim EndWeekDayOfYear As Integer = _
DirectCast(New DateTime(inDate.Year, DEC, LASTDAYOFDEC).DayOfWeek, Integer)

' Compensate for the fact that we are using monday
' as the first day of the week
If StartWeekDayOfYear = 0 Then
StartWeekDayOfYear = 7
End If
If EndWeekDayOfYear = 0 Then
EndWeekDayOfYear = 7
End If

' Calculate the number of days in the first and last week
Dim DaysInFirstWeek As Integer = 8 - StartWeekDayOfYear
Dim DaysInLastWeek As Integer = 8 - EndWeekDayOfYear

' If the year either starts or ends on a thursday it will have a 53rd week
If StartWeekDayOfYear = THURSDAY OrElse EndWeekDayOfYear = THURSDAY Then
ThursdayFlag = True
End If

' We begin by calculating the number of FULL weeks
' between the start of the year and
' our date. The number is rounded up, so the smallest possible value is 0.
Dim FullWeeks As Integer = _
CType(Math.Ceiling((DayOfYear - DaysInFirstWeek) / 7), Integer)

Dim WeekNumber As Integer = FullWeeks

' If the first week of the year has at least four days,
' then the actual week number for our date
' can be incremented by one.
If DaysInFirstWeek >= THURSDAY Then
WeekNumber = WeekNumber + 1
End If

' If week number is larger than week 52
' (and the year doesn't either start or end on a thursday)
' then the correct week number is 1.
If WeekNumber > 52 AndAlso Not ThursdayFlag Then
WeekNumber = 1
End If

' If week number is still 0,
' it means that we are trying to evaluate the week number for a
' week that belongs in the previous year
' (since that week has 3 days or less in our date's year).
' We therefore make a recursive call using the last day of the previous year.
If WeekNumber = 0 Then
WeekNumber = GetWeekNumber( _
New DateTime(inDate.Year - 1, DEC, LASTDAYOFDEC))
End If

Return WeekNumber
End Function

Monday, April 20, 2009

VB.Net - Get Weeks In a Year


Public Function GetWeeksInYear(ByVal dayofsunday As DateTime) As Integer

Dim dayofthursday As DateTime = dayofsunday.AddDays(-3)
Dim yearno As Integer = dayofthursday.Year
Dim firstday As DateTime = "01-Jan-" & yearno.ToString

Dim totalweeks As Integer = 0

If firstday.DayOfWeek = DayOfWeek.Thursday Then
totalweeks = 53
ElseIf Date.IsLeapYear(yearno) = True _
And firstday.DayOfWeek = DayOfWeek.Wednesday Then
totalweeks = 53
Else
totalweeks = 52
End If

Return totalweeks
End Function

Wednesday, April 1, 2009

VB.Net - Get Directory / Folder Size


Public Function GetFolderSize(ByVal path As String, _
ByVal includeSubFolders As Boolean) As Long

GetFolderSize = 0

Dim main_dir As New System.IO.DirectoryInfo(path)
Dim dir_files() As FileInfo

If includeSubFolders Then
dir_files = main_dir.GetFiles("*", SearchOption.AllDirectories)
Else
dir_files = main_dir.GetFiles("*", SearchOption.TopDirectoryOnly)
End If

For Each ofile As IO.FileInfo In dir_files
GetFolderSize = GetFolderSize + ofile.Length
Next

End Function

Tuesday, March 3, 2009

ASP.Net Print Posted Values

Create two web forms, one name posting.aspx and another is posted.aspx, on the posing.aspx place different web controls like text boxes, dropdown list, etc
When finished, open the source view of posting.aspx and set the action property of the form tag to "posted.aspx", this will direct the page to post values to the posted.aspx page. Dont forget to place a submit button on posting.aspx page, so we click to post the values.

Posting.aspx page:
(a). Here you will add all user input controls
(b). place a submit button
(c). Set action property of the form to "posted.aspx"
(d). Set method property of the form to either post of get

Posted.aspx:
Now create the posted.aspx page and simply place the below code in the source of posted.aspx page.

<%For Each skey As String In Me.Request.Form.Keys%>
<%sKey%>=<%Request.Form.Get(sKey)%>
<%Next %>

This code will print out all the posted parameters with the name and values.
Only those parameters will be posted for which value is set or entered by the user.
Now click submit and see the result, you will find list of parameters with there values.

Sunday, March 1, 2009

Javascript include from ASP.NET server control

In ASP.NET 2.0 the Page object has a Header property - which contains a Controls collection. This is good news since it makes it possible to (easily) inject a <script type="text/javascript" src="whatever"> into the <head></head> section of the resulting HTML page.

You can - for example from the code of your custom server control - add a htmlgeneric control to the containing page header control like this:

string sInclude = "~/specialincludes/blabla.js";
sInclude = ResolveUrl( sInclude );
HtmlGenericControl Include = new HtmlGenericControl("script");
Include.Attributes.Add("type", "text/javascript");
Include.Attributes.Add("src", sInclude);
this.Page.Header.Controls.Add(Include);
and that would make the resulting html code look like this:

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" src="/thesite/specialincludes/blabla.js">
</script>
<head>

IIS Worker Process and Application Pooling

Web server?
IIS (Internet Information Service) running on a software port like 80 for Http and 443 for Https or any other port set bt the administrator, it can host more than one web site and each web site can hold more than one web application. Web server provides application pooling and hanldes all web request from the internet and forward it to respective web site's application pool for processing and response. IIS can host classic asp applications, asp.net applications, php applications, etc.

Application Pooling?
The Windows IIS web server, has application pools where different web applications or web sites can be pooled. When we say pooled it means it is loaded in the process, so the web requests are processed. Why pooling? becuase the application will handle multiple web requests, the application is loaded once, and remains in the pool for quite some time to process subsequent requests and when remains idel for too long it is unloded. The pooling helps better manage server resources, so the CPU and Memory is not consumed uselessly. An application pool can hold more than one web application, and IIS can have more than one application pools. Application pools it self is comprehensive topic and it provides many things to tune your web application performace.

Worker Process?
As we discussed above, application pooling is done in IIS, Worker Process is actually a program that executes in the system memory for a specific application pool, if we have three application pools and the pools are active than we will have three process running it the system memory, these are the processes which handle the requests and send response. The "w3wp.exe" program can be easily found in the task manager, this is the program running behind the application pool.
We can define more than one worker process in an application pool, by default we have one worker process in an application pool, this means there is only one queue for my web requests, so ten request will execute one at a time.
If i increase the number to 2, so now my application pool has 2 worker process, this means there are two queues for my web requests, so ten request will execute two at a time. Ofcourse the CPU time will be divied between the two worker processes, this means to many worker processes will cut down the overall response time if i have a moderate server, therefore it depends upon the hardware of the server that how many worker processes it can hold.

Thursday, February 5, 2009

Logon Info and Parameter Value for Crystal reports

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Sub SetLogonInfo(ByRef objrpt As ReportDocument)

Dim connection As IConnectionInfo
Dim newServerName As String = "dbServer"
Dim newDatabaseName As String = "dbName"

Dim userID As String = "dbusername"
Dim password As String = "dbpassword"

' Change the server name and database in main reports

For Each connection In objrpt.DataSourceConnections
' SetConnection can also be used to set
' new logon and new database table
objrpt.DataSourceConnections(connection.ServerName, _
connection.DatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
Next

' Change the server name and database in subreports
Dim subreport As ReportDocument

For Each subreport In objrpt.Subreports

For Each connection In subreport.DataSourceConnections

' SetConnection can also be used to set
' new logon and new database table
subreport.DataSourceConnections(connection.ServerName, _
connection.DatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
Next

Next

End Sub


Public Sub SetParameterValue(ByRef objRPT As ReportDocument, _
ByVal parameterName As String, _
ByVal ParameterValue As String)

Dim parameterField As ParameterField

parameterField = objRPT.ParameterFields(parameterName)
parameterField.CurrentValues.AddValue(ParameterValue)
parameterField.HasCurrentValue = True

End Sub

Sunday, February 1, 2009

ASP.Net "Index was outside the bounds of the array" Publish Website Issue

With Visual Studio SP1 when they use the "Publish Website" command with a web project configured to use the built-in ASP.NET Development Web Server with a "/" as the virtual path encounter an "Index was outside the bounds of the array" error message during publishing:



This is a bug as regression in VS 2005 SP1, for this we a public hotfix for the issue that you can directly download here

Failed to access IIS metabase problem

When you install IIS AFTER .NET 2.0 framework, the rights of the ASPNET user had not been set correctly.

Repair (Uninstall if repair does not work for you) .NET Framework 2.0

Simply run the following from command line to reset the IIS registry settings for aspnet user. Usually framework directory for .Net Framework 2.0 resides under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -i

Reference: http://support.microsoft.com/?kbid=267904

On Vista and VS 2005 check the shortcut to VS 2005, and make sure 'Run as Administrator' option is checked. If not check this option in Advance section.