Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Saturday, March 31, 2012

System.Drawing: Error when using a .bmp or .gif file but not when .jpg

I each time get errors when I use an .bmp or ,.gif file as source but
whenever I use a .jpg file it works perfect.
Why is that? and how to fix it?
I almost have no knowledge about the system.drawing and so I am in the dark
about this.
This is my code
--
<%@dotnet.itags.org. Page Language="vb" %>
<%@dotnet.itags.org. import namespace="system.drawing" %>
<%@dotnet.itags.org. import namespace="system.drawing.imaging" %>
<%@dotnet.itags.org. import namespace="system.drawing.drawing2d" %>
<%
' initialise objects
dim strFilename as string
dim b as New System.Drawing.Bitmap(server.mappath("test.jpg"))
dim g as graphics = graphics.fromimage(b)
g.smoothingMode = smoothingMode.antiAlias
dim stringFormat As New StringFormat()
g.drawString("The Magic Word", New font("arial",3),systembrushes.windowtext,
New pointF(2,2), stringFormat)
' Set the content type
response.contenttype="image/jpeg"
' send the image to the viewer
b.save(response.outputstream, b.rawformat)
' tidy up
b.dispose()
%>Hi Richard,
As for the "A Graphics object cannot be created from an image that has an
indexed pixel format" error, it is caused by the Graphic object can't been
created from some certain image format which contains indexed pixel. I've
done some tests and one means is load the image and convert it into jpeg
format first and then create Graphich object to manipulate it. For example,
here is my test code:
========================================
==========
Private Sub Output_Image(ByVal path As String)
Try
Dim img As Image = Image.FromFile(path)
Dim stream As New System.IO.MemoryStream
img.Save(stream, ImageFormat.Jpeg)
Dim imgNew As Image = Image.FromStream(stream)
Dim g As Graphics = Graphics.FromImage(imgNew)
g.DrawString("MS Test", New Font("Verdana", 20,
FontStyle.Bold), _
New SolidBrush(Color.Beige), 0, 0)
Response.Clear()
Response.ContentType = "Image/jpeg"
imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()
img.Dispose()
stream.Close()
imgNew.Dispose()
Catch ex As Exception
Response.Write("<br>" + ex.Message)
End Try
End Sub
========================================
=========
Please have a try to see whether it works for you. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
thx a lot, this really helped me out.
I got no errors and with some thinking I made sure ppl can't link to my
files. (put a http://www. infront of url to view)
digifan.nl/ShowGalleryImage.aspx? img=Jlz1wB3JMO636rzX3rGMrpOK7mbHBTzFQQ1O
Q%2
fJ5V3Y%3d
and looking at the properties of the image it shows:
digifan.nl/ShowFullImage.aspx? img=Jlz1wB3JMO636rzX3rGMrpOK7mbHBTzFQQ1O
Q%2fJ5
V3Y%3d
which is only the image.
Again thx, i am going to read a bit some more about the system.drawing and
what it al can do but now i have an understanding of
the general thing.
Richard
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> schreef in bericht
news:VQpV0n2UEHA.3204@.cpmsftngxa10.phx.gbl...
> Hi Richard,
> As for the "A Graphics object cannot be created from an image that has an
> indexed pixel format" error, it is caused by the Graphic object can't been
> created from some certain image format which contains indexed pixel. I've
> done some tests and one means is load the image and convert it into jpeg
> format first and then create Graphich object to manipulate it. For
example,
> here is my test code:
> ========================================
==========
> Private Sub Output_Image(ByVal path As String)
> Try
> Dim img As Image = Image.FromFile(path)
> Dim stream As New System.IO.MemoryStream
> img.Save(stream, ImageFormat.Jpeg)
> Dim imgNew As Image = Image.FromStream(stream)
> Dim g As Graphics = Graphics.FromImage(imgNew)
> g.DrawString("MS Test", New Font("Verdana", 20,
> FontStyle.Bold), _
> New SolidBrush(Color.Beige), 0, 0)
> Response.Clear()
> Response.ContentType = "Image/jpeg"
> imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
> Response.End()
>
> img.Dispose()
> stream.Close()
> imgNew.Dispose()
> Catch ex As Exception
> Response.Write("<br>" + ex.Message)
> End Try
> End Sub
> ========================================
=========
> Please have a try to see whether it works for you. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
>

System.Drawing: Error when using a .bmp or .gif file but not when .jpg

I each time get errors when I use an .bmp or ,.gif file as source but
whenever I use a .jpg file it works perfect.
Why is that? and how to fix it?

I almost have no knowledge about the system.drawing and so I am in the dark
about this.

This is my code
-----------

<%@dotnet.itags.org. Page Language="vb" %>
<%@dotnet.itags.org. import namespace="system.drawing" %>
<%@dotnet.itags.org. import namespace="system.drawing.imaging" %>
<%@dotnet.itags.org. import namespace="system.drawing.drawing2d" %>
<%

' initialise objects
dim strFilename as string
dim b as New System.Drawing.Bitmap(server.mappath("test.jpg"))
dim g as graphics = graphics.fromimage(b)
g.smoothingMode = smoothingMode.antiAlias
dim stringFormat As New StringFormat()
g.drawString("The Magic Word", New font("arial",3),systembrushes.windowtext,
New pointF(2,2), stringFormat)

' Set the content type
response.contenttype="image/jpeg"

' send the image to the viewer
b.save(response.outputstream, b.rawformat)

' tidy up
b.dispose()

%thx a lot, this really helped me out.

I got no errors and with some thinking I made sure ppl can't link to my
files. (put a http://www. infront of url to view)

digifan.nl/ShowGalleryImage.aspx?img=Jlz1wB3JMO636rzX3rGMrpOK 7mbHBTzFQQ1OQ%2
fJ5V3Y%3d

and looking at the properties of the image it shows:

digifan.nl/ShowFullImage.aspx?img=Jlz1wB3JMO636rzX3rGMrpOK7mb HBTzFQQ1OQ%2fJ5
V3Y%3d

which is only the image.

Again thx, i am going to read a bit some more about the system.drawing and
what it al can do but now i have an understanding of
the general thing.

Richard

"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> schreef in bericht
news:VQpV0n2UEHA.3204@.cpmsftngxa10.phx.gbl...
> Hi Richard,
> As for the "A Graphics object cannot be created from an image that has an
> indexed pixel format" error, it is caused by the Graphic object can't been
> created from some certain image format which contains indexed pixel. I've
> done some tests and one means is load the image and convert it into jpeg
> format first and then create Graphich object to manipulate it. For
example,
> here is my test code:
> ==================================================
> Private Sub Output_Image(ByVal path As String)
> Try
> Dim img As Image = Image.FromFile(path)
> Dim stream As New System.IO.MemoryStream
> img.Save(stream, ImageFormat.Jpeg)
> Dim imgNew As Image = Image.FromStream(stream)
> Dim g As Graphics = Graphics.FromImage(imgNew)
> g.DrawString("MS Test", New Font("Verdana", 20,
> FontStyle.Bold), _
> New SolidBrush(Color.Beige), 0, 0)
> Response.Clear()
> Response.ContentType = "Image/jpeg"
> imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
> Response.End()
>
> img.Dispose()
> stream.Close()
> imgNew.Dispose()
> Catch ex As Exception
> Response.Write("<br>" + ex.Message)
> End Try
> End Sub
> =================================================
> Please have a try to see whether it works for you. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Richard,

As for the "A Graphics object cannot be created from an image that has an
indexed pixel format" error, it is caused by the Graphic object can't been
created from some certain image format which contains indexed pixel. I've
done some tests and one means is load the image and convert it into jpeg
format first and then create Graphich object to manipulate it. For example,
here is my test code:
==================================================
Private Sub Output_Image(ByVal path As String)
Try

Dim img As Image = Image.FromFile(path)
Dim stream As New System.IO.MemoryStream
img.Save(stream, ImageFormat.Jpeg)
Dim imgNew As Image = Image.FromStream(stream)

Dim g As Graphics = Graphics.FromImage(imgNew)

g.DrawString("MS Test", New Font("Verdana", 20,
FontStyle.Bold), _
New SolidBrush(Color.Beige), 0, 0)

Response.Clear()
Response.ContentType = "Image/jpeg"

imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()

img.Dispose()
stream.Close()
imgNew.Dispose()

Catch ex As Exception
Response.Write("<br>" + ex.Message)
End Try

End Sub
=================================================

Please have a try to see whether it works for you. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

system.enterpriseservices.dll error

I am running a web app on w2k3/IIS 6.0/ASP.net 2.0. This app runs fine on a different server. The error message I get is

Compiler Error Message:CS0006: Metadata file 'C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll' could not be found

I have seen solutions to remove the "<identity impersonate="true" />" setting from the web.config file. That has not been helpful. Another solution was to delete the system.enterpriseservices.dll from C:\Windows\assembly. I have deleted the file, copied a new .dll, and that did not work. I have reinstalled IIS and ASP.Net 2.0 as well. So far, no dice. Any other ideas are greatly welcomed!


AJ

Hello AJ,

This may be a dumb question, but is the assembly in the GAC on the deployment server? If it isn't, you should be able to add it by running "gacutil /if System.EnterpriseServices.dll" using the 2.0 version of gacutil.exe.

HTH,
Clay


Clay,

Thanks for the response. I just got the problem figured out today.

The file permissions were screwed up. Users did not have read and execute permissions to this folder:
C:\WINDOWS\WinSxS\x86_System.EnterpriseServices_b03f5f7f11d50a3a_2.0.0.0_x-ww_7d5f3790

After I fixed that I got a similar error message as before but it mentioned a system.enterpriseServices.Wrapper.dll and found out that this file was missing
C:\WINDOWS\WinSxS\x86_System.EnterpriseServices_b03f5f7f11d50a3a_2.0.0.0_x-ww_7d5f3790\System.EnterpriseServices.Wrapper.dll

Now it is running like a champ!

AJ

System.FormatException: Index (zero based) must be greater than or equal to zero

Hi

I am absolutely out of my wits on how to handle this problem. I'm just beginning to learn ASP.NEt.

I get this error while trying to insert new registration info on an access table:

System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

Here's my code:

Dim cmdInsert as OleDbCommand
Dim strInsert as String
strInsert="Insert into Userdetail (login_id,password, Name, Designation, Company, " _
& "Address, Zip, City, Country, Fax, email, phone, employee_size, sales)" _
& " VALUES (@dotnet.itags.org.loginid, @dotnet.itags.org.password, @dotnet.itags.org.Name, @dotnet.itags.org.Designation,@dotnet.itags.org.Company," _
& " @dotnet.itags.org.Address, @dotnet.itags.org.Zip, @dotnet.itags.org.City, @dotnet.itags.org.Country,@dotnet.itags.org.Fax,@dotnet.itags.org.Email,@dotnet.itags.org.Phone,@dotnet.itags.org.EmployeeSize,@dotnet.itags.org.Sales)"
cmdInsert= New OleDbCommand(strInsert,conUser)
cmdInsert.Parameters.Add("@dotnet.itags.org.loginid", txtLoginID.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Password", txtPassword.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Name", txtName.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Designation", txtDesignation.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Company", txtCompany.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Address", txtAddress.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Zip", txtZip.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.City", txtCity)
cmdInsert.Parameters.Add("@dotnet.itags.org.Country", txtCountry.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Fax", txtFax.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Email", txtEmail.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Phone", txtPhone.text)
cmdInsert.Parameters.Add("@dotnet.itags.org.EmployeeSize", rbEmployeeSize.SelectedItem.Text)
cmdInsert.Parameters.Add("@dotnet.itags.org.Sales", rbSalesSize.SelectedItem.Text)
conUser.Open()
cmdInsert.ExecuteNonQuery()
conUser.Close()

Help! Please... :(I think it is something to do with rbEmployeeSize.SelectedItem.Text or/and rbSalesSize.SelectedItem.Text - what are the controls that relate to these?

DJ
I think it is something to do with rbEmployeeSize.SelectedItem.Text or/and rbSalesSize.SelectedItem.Text - what are the controls that relate to these?
These are RadioButtonLists that give out the value of the text of the Radio Button.
It may seem like a silly question but has there been an item selected in either list? - if not then the SelectedIndex property is null and therefore the Index (zero based) is not greater than or equal to zero or less than the size of the argument list.

Maybe worth adding some code to check an item was selected.

DJ
Yes, the radio buttons are being selected.

I just checked if the item was being selected and found that both of them are being selected.

Here's the html script to define asp form controls:

<form runat="server">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td colspan="2"><strong>Enter Registration Detail</strong></td>
</tr>
<tr>
<td width="18%">Login ID</td>
<td width="82%"><asp:textbox ID="txtLoginID" runat="server" />
<asp:Label ID="lblMessage" runat="server" />
<asp:requiredfieldvalidator
ControlToValidate="txtLoginID"
Text="Login ID Field Cannot be left Blank"
runat="server" />

</td>
</tr>
<tr>
<td>Password</td>
<td><asp:textbox ID="txtPassword" MaxLength="20" runat="server" TextMode="Password" />
<asp:requiredfieldvalidator
ControlToValidate="txtPassword"
Text="Password Cannot be left Blank"
runat="server" /> <asp:regularexpressionvalidator
ControlToValidate="txtPassword"
Text= "Your Password must contain between 3 and 20 characters!"
ValidationExpression="\w{3,30}"
runat="server" /> <asp:comparevalidator
ControlToValidate="txtPassWord"
ControlToCompare="txtConfirmPassword"
Text="Please Reconfirm your password"
Operator="Equal"
Type="String"
runat="server" /> </td>
</tr>
<tr>
<td>Confirm Password</td>
<td><asp:textbox ID="txtConfirmPassword" MaxLength="20" runat="server" TextMode="Password" />
<asp:requiredfieldvalidator ControlToValidate="txtConfirmPassword" Text="Please Reconfirm the password" runat="server" /> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Name</td>
<td><asp:textbox ID="txtName" runat="server" /> <asp:requiredfieldvalidator ControlToValidate="txtName" Text="Name Cannot be left Blank" runat="server" /> </td>
</tr>
<tr>
<td>Designation</td>
<td><asp:textbox ID="txtDesignation" runat="server" /> </td>
</tr>
<tr>
<td>Company</td>
<td><asp:textbox ID="txtCompany" runat="server" /> </td>
</tr>
<tr>
<td>Address</td>
<td> <asp:textbox Columns="30" ID="txtAddress" Rows="4" runat="server" TextMode="MultiLine" />
<asp:requiredfieldvalidator ControlToValidate="txtAddress" Text="Address Cannot be left Blank" runat="server" /> </td>
</tr>
<tr>
<td>City</td>
<td><asp:textbox ID="txtCity" runat="server" /> </td>
</tr>
<tr>
<td>Zip</td>
<td><asp:textbox ID="txtZip" runat="server" /> </tr>
<tr>
<td>Country</td>
<td><asp:textbox ID="txtCountry" runat="server" /> </tr>
<tr>
<td>Fax</td>
<td><asp:textbox ID="txtFax" runat="server" /> </tr>
<tr>
<td>Email</td>
<td><asp:textbox ID="txtEmail" runat="server" /> <asp:regularexpressionvalidator
ControlToValidate="txtEmail"
Text="Invalid Email Address"
Display="Dynamic"
ValidationExpression="\S+@.\S+\.\S{2,3}"
runat="server" /> </tr>
<tr>
<td>Phone</td>
<td><asp:textbox ID="txtPhone" runat="server" /> </tr>
<tr>
<td>Employee Size</td>
<td>
<asp:radiobuttonlist
ID="rbEmployeeSize"
runat="server" >
<asp:ListItem Text="Less Than 10" />
<asp:ListItem Text="10 to 49" />
<asp:listitem Text="50 to 100" />
<asp:listItem text= "Over 50" />
</asp:radiobuttonlist></td>
</tr>
<tr>
<td>Sales Size</td>
<td><asp:radiobuttonlist
ID="rbSalesSize"
runat="server" >
<asp:ListItem Text="Less Than 50,000" />
<asp:ListItem Text="50,000 to 100,000" />
<asp:listitem Text="100,000 to 100" />
<asp:listItem text= "Over 50" /> </asp:radiobuttonlist></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><asp:button ID="Submit" OnClick="CheckLogin" runat="server" Text="Submit" /></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
Hi DJ4UK,

I just found out the problem. The problem was in my Parameter.Add Declaration of @.City where I was not assigning the value of txtCity (should have been TxtCity.Text)

But now I get a Syntax error in INSERT INTO Statement:

System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.

This seems to be a very simple insert statement. What could possibly be wrong here?
I just found out the solution to the second problem too. I was using a reserved word password in the Database and I had to use [] to resolve this.

Thanks for looking into my problem.

Diban

System.FormatException: Input string was not in a correct format.

Strange error mblè mblè :)


Dim SQL = "SELECT confermato, confrndnum FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs
Dim RsCommand = New OleDbCommand(Sql, Conn)
Dim RsRecordCount = RsCommand.ExecuteScalar()

If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie = Request.Cookies("tristizia_auth")
ltrUsername.Text = ReadCookie("Username")
divConfOp.Visible = TRUE
End If


the line "If RsRecordCount = 0 Then" gives error
The error is strange becouse if RsRecordCount is 0 the page works, if not it gives the error

Thanks for any answer
Bye
. AtariVerify that the following line is not returning NULL. If it is and you are trying to put it into a string then it won't work of course. The line below is defiantely your problem I think though.


ltrUsername.Text = ReadCookie("Username")

Ok tryed, but the error appears =

I tryed either so:


If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie = Request.Cookies("tristizia_auth")
If Not ReadCookie Is Nothing Then
ltrUsername.Text = ReadCookie("Username")
Else
ltrUsername.Text = "[Unsknown]"
End If
divConfOp.Visible = TRUE
End If

But however I get error either so :


If RsRecordCount = 0 Then
divErrEx.Visible = True
Else
Dim MyVar = "ewruowehr"
End If

Boh?!?!

Bye
. Atari
One more victim of the Visual Basic type sloppiness (which is a feature).
Try to Dim ReadCookie as HttpCookie, just to be sure you don't get a string instead.
Uhm nothing is changed...


Dim Conn = New OleDbConnection("Provider = Microsoft.Jet.OleDb.4.0;Data Source=" & Server.MapPath("/mdb-database/tristizia.mdb"))
Conn.Open()
Dim SQL = "SELECT confermato, confrndnum FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs
Dim RsCommand = New OleDbCommand(Sql, Conn)
Dim RsRecordCount = RsCommand.ExecuteScalar()

<b style="color:red;">If RsRecordCount = 0 Then</b>
divErrEx.Visible = True
Else
SQL = "UPDATE utenti SET confermato = 'true' WHERE ConfRndNum = " & QS
RsCommand = New OleDbCommand(Sql, Conn)
RsCommand.ExecuteNonQuery()
Dim ReadCookie As HttpCookie = Request.Cookies("tristizia_auth")
If Not ReadCookie Is Nothing Then
ltrUsername.Text = ReadCookie("Username")
Else
ltrUsername.Text = "[Sconosciuto]"
End If
divConfOp.Visible = TRUE
End If

But what's the problem? I need to declare AS [type] the variables ? If so what's RsRecordCount ? I tryed As Integer but doesn't work...

Bye
. Atari
It's always better to declare the type of your variables. Not declaring it is a source of bugs.
Why do you use ExecuteScalar here, whereas your query returns two different columns? ExecuteScalar returns the first column of the first row. Here, it would be confermato. Is this column an integer?
In this case, you can Dim RsRecordCount as Integer = CType(RsCommand.ExecuteScalar(), Integer), but I suspect this is not what you're trying to do...
Your query should probably be "SELECT COUNT(*) FROM utenti WHERE confermato = 'false' AND confrndnum = " & Qs

System.FormatException: Input String was not in a correct format.

I've got an error "System.FormatException: Input string was not in a correct
format." while I'm implementing a datagrid and a textbox
What's wrong with it?

Sub Button1_Click(sender As Object, e As EventArgs)
DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
DataGrid1.DataBind()
End Sub

Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
Dim connectionString As String = "server='localhost'; user id='******';
password='******'; database='******'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
([Software].[Others] like @dotnet.itags.org.Others)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_others As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_others.ParameterName = "@dotnet.itags.org.Others" dbParam_others.Value = others
dbParam_others.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_others)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet

End FunctionI would guess it is something to do with converting the TextBox1.Text to an
int data type. The textbox could potentially contain a value other than a
numeric value. This would cause this error. Also, MyQueryMethod looks like
it is expecting a value of a string data type. Since you are converting
TextBox1.Text to an int type, this may also cause the error.

-Darrin

"sbox" <s@.b.x> wrote in message
news:%23ibArp48DHA.712@.tk2msftngp13.phx.gbl...
> I've got an error "System.FormatException: Input string was not in a
correct
> format." while I'm implementing a datagrid and a textbox
> What's wrong with it?
> Sub Button1_Click(sender As Object, e As EventArgs)
> DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
> DataGrid1.DataBind()
> End Sub
> Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
> Dim connectionString As String = "server='localhost'; user
id='******';
> password='******'; database='******'"
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
> ([Software].[Others] like @.Others)"
> Dim dbCommand As System.Data.IDbCommand = New
> System.Data.SqlClient.SqlCommand
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> Dim dbParam_others As System.Data.IDataParameter = New
> System.Data.SqlClient.SqlParameter
> dbParam_others.ParameterName = "@.Others" dbParam_others.Value = others
> dbParam_others.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_others)
> Dim dataAdapter As System.Data.IDbDataAdapter = New
> System.Data.SqlClient.SqlDataAdapter
> dataAdapter.SelectCommand = dbCommand
> Dim dataSet As System.Data.DataSet = New System.Data.DataSet
> dataAdapter.Fill(dataSet)
> Return dataSet
> End Function
You should not have the ' ' in your connection string. Take a look at the
connection strings at

http://www.able-consulting.com/dotn...ManagedProvider

Ben Miller

--
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

"sbox" <s@.b.x> wrote in message
news:%23ibArp48DHA.712@.tk2msftngp13.phx.gbl...
> I've got an error "System.FormatException: Input string was not in a
correct
> format." while I'm implementing a datagrid and a textbox
> What's wrong with it?
> Sub Button1_Click(sender As Object, e As EventArgs)
> DataGrid1.DataSource = MyQueryMethod(CInt(TextBox1.Text))
> DataGrid1.DataBind()
> End Sub
> Function MyQueryMethod(ByVal others As String) As System.Data.DataSet
> Dim connectionString As String = "server='localhost'; user
id='******';
> password='******'; database='******'"
> Dim dbConnection As System.Data.IDbConnection = New
> System.Data.SqlClient.SqlConnection(connectionStri ng)
> Dim queryString As String = "SELECT [Software].* FROM [Software] WHERE
> ([Software].[Others] like @.Others)"
> Dim dbCommand As System.Data.IDbCommand = New
> System.Data.SqlClient.SqlCommand
> dbCommand.CommandText = queryString
> dbCommand.Connection = dbConnection
> Dim dbParam_others As System.Data.IDataParameter = New
> System.Data.SqlClient.SqlParameter
> dbParam_others.ParameterName = "@.Others" dbParam_others.Value = others
> dbParam_others.DbType = System.Data.DbType.String
> dbCommand.Parameters.Add(dbParam_others)
> Dim dataAdapter As System.Data.IDbDataAdapter = New
> System.Data.SqlClient.SqlDataAdapter
> dataAdapter.SelectCommand = dbCommand
> Dim dataSet As System.Data.DataSet = New System.Data.DataSet
> dataAdapter.Fill(dataSet)
> Return dataSet
> End Function

System.FormatException: Input string was not in a correct format

I am getting above error

// Validate input
if ((userId.Trim() == string.Empty) || (password.Trim() == string.Empty))
return null;

// Get an instance of the account DAC using the DACFactory
IUserAccount dac = CData.DACFactory.FDACUserAccount.Create();

//On this line i am getting error.userId and Password are strings
UserAccountInfo userAccount = dac.Login(userId , password);
return userAccount;

Please sort out my problemI have made three assemblies. 1 is calling 2nd and 2nd is calling 3rd.
now when i call methods of 3rd from 1st through 2nd one i get "System.FormatException: Input string was not in a correct format" on every string manipulation. Even if it is throwing exceptions in string formats it gives that exception
When you use the Trim method, it expects the variable to be a string. When your variable is null, the Trim method would throw that FormatException. So you should rewrite your code to test your variable again null instead.
Ex:
<code>
if( userID == null )
{
//do something here
}

System.IndexOutOfRangeException

I'm seeing the above error message appear on a web form. All the formcode-behind does is grab data from a SQL Server db (2005 Beta) andwrite it out in specfied controls.
The line that throws up the error is the following:
<code>
Line 150: txtCoDeath1a.Text = dtr("COD1a")
</code>
'Dtr' is simply a datareader that has been initialised previously. Iknow I should be checking for nulls in the db, but that isn't theproblem in this instant as the record I'm grabbing does have data forthe field 'COD1a'. It's of type nvarchar, length 150.
I've googled this error and have not found anything that seems directly relevant.
I'm using VB.
Any help much appreciated.

try putting this before your code

if dtr.Read then
dtr("COD1a")
end if


Sorry Chris, I should've posted more of my code.
I already have those lines in the code.
Any other ideas?

Try this

if not System.DBNull(dtr("COD1a")) then

txtCoDeath1a.Text = dtr("COD1a")

end if

Could you post more of your code? Are results coming back from the database? Is there a field called COD1a?


Thanks for the help guys, but I've located the source of theproblem. Very simple; I'd misnamed 'Cod1a'. Its actually 'CodIa'. Spotthe difference? Neither did I for a while!
<Sheepish> Sorry and thanks again.

System.IndexOutOfRangeException: There is no row at position 0

I'm getting a frustrating error that I can't seem to figure out with an update button. However, when I try to execute the Submit_Click sub I get the error that is the subject of this post. Can you see anything wrong with my code? The GetRecord sub work great on page_load to get the record in the first place, but in re-calling it it's not working.

Please help if you can, thanks!

Oh, E_ID refers to a context item (Dim E_ID as String = Context.Items("EmailID"))


Sub Submit_Click(Sender As Object, E As EventArgs)
GetRecord(E_ID)
Row = IndividualDS.Tables("Individual").Rows(0)
Row.Item("F_name") = FirstNameText.Text

Adapter.Update(IndividualDS, "Individual")
End Sub

Sub GetRecord(E_ID As String)
SelectStatement = "Select * From Individual Where Email='" & _
E_ID & "'"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("policy_dir.mdb")

Connect.ConnectionString = ConnectString
Adapter.SelectCommand = _
New OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open
IndividualCB = New OleDBCommandBuilder(Adapter)
Adapter.Fill(IndividualDS, "Individual")
Adapter.SelectCommand.Connection.Close
End Sub

You may find some helphere.
Thank you, that did help.

I am closer... I am now getting an error that says "operation must use an updateable query" what should I check for to correct this?
Check the search result in Google.
Thanks, I think i got it fixed

System.IndexOutOfRangeException: Index was outside the bounds of the array

Hi i am getting the following error "System.IndexOutOfRangeException: Index was outside the bounds of the array". it is coming from this line of code ;

Line 595: // Build Column Name PartLine 596: strPart1 = strPart1 + "`" + strData[lngIter, 0] + "`,";Line 597:
It may have been caused by the following code;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

 


You will get this if you use an index that is higher than the number of items in the array. So check if the lngIter is within the index range of the array so you don't pass an index which is higher than the total amount of items in the array.


Hi, i am quite new to programming, so i am unsure if i have declared the arrays properly, however i will show you some code and if you could tell me if you can identify where i have to declare the array.;

The following code is in the page calling up a method;

clsOBJ objDHOC =newclsOBJ();

Pmillio.clsOBJ.buildQuery("INSERT","tblProperty", strData, strWhere,"","1","1","strData");

string[,] strData =newstring[11, 2];

string[,] strWhere =newstring[11, 3];

strData[0, 0] ="StatutoryDate";

strData[0, 1] = txtDate.Text;

The following code is what in the DAL which the one above is referencing;

staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

// Ucase

strAction = (strAction);

// Dimension

string strSQL;

int lngIter;

string strPart1 =null;

string strPart2 =null;

System.InvalidCastException

Hope someone can help. I am trying to get a submit button working and
getting this error now System.InvalidCastException: Object must implement
IConvertible. This is showing up on the ExecuteNonQuery line. Below is the
code that I have in my Page_load. I also have no idea of what code I would
use in the Submit_Click event to get the insert to work. Any help would be
appreciated
OleDbConnection conn = new
OleDbConnection("Provider=OraOLEDB.Oracle.1;Persist Security
Info=False;"+"User ID=conference;Password=conf00;Data
Source=ntdrp001.world;");
OleDbCommand command = new OleDbCommand("CONF-REQUEST_INSERT", conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value =
DropDownList1;
command.Parameters.Add("DropDownList2", OleDbType.VarChar).Value =
DropDownList2;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value =
txtEStartDate;
command.Parameters.Add("txtEEndDate", OleDbType.Date).Value = txtEEndDate;
command.Parameters.Add("txtEStartTime", OleDbType.Numeric).Value =
txtEStartTime;
command.Parameters.Add("txtEEndTime", OleDbType.Numeric).Value =
txtEEndTime;
command.Parameters.Add("txtEventName", OleDbType.VarChar).Value =
txtEventName;
command.Parameters.Add("txtEventSize", OleDbType.Numeric).Value =
txtEventSize;
command.Parameters.Add("txtSStartDate", OleDbType.Date).Value =
txtSStartDate;
command.Parameters.Add("txtSStartTime", OleDbType.Numeric).Value =
txtSStartTime;
command.Parameters.Add("txtEventDescription", OleDbType.VarChar).Value =
txtEventDescription;
command.Parameters.Add("txtSpecialRequirements", OleDbType.VarChar).Value =
txtSpecialRequirements;
conn.Open();
int rows = command.ExecuteNonQuery();
conn.Close();Hi, Brian,
The reason is that you directly use the web control objects for the value as
signments. You have to use their properties. like:
command.Parameters.Add("DropDownList1", OleDbType.VarChar).Value = DropDownL
ist1.SelectedItem.Value;
command.Parameters.Add("txtEStartDate", OleDbType.Date).Value = txtEStartDat
e.Text;
Bin Song, MCP

System.InvalidCastException: Error de QueryInterface para la interfaz GrosConexion._ClaFun

Hi,
I'km newbie in asp.net. My problem is the subject of this post 'System.InvalidCastException: Error de QueryInterface para la interfaz GrosConexion._ClaFunciones'
I have a dll from a software provider, and i must use your functions from an asp page. My code is (in Page_Load Event of a webform)

Dim RPSGrosVariablesAs GrosVariablesGenererales.ClaVariables

RPSGrosVariables =New GrosVariablesGenererales.ClaVariables

Dim RPSGrosConexionAs GrosConexion.ClaFunciones

RPSGrosConexion =New GrosConexion.ClaFunciones

IfNot IsPostBackThen

gblRutaINI = System.Web.HttpRuntime.AppDomainAppPath & "Prueba.INI"

TextBox1.Text = gblRutaINI

If RPSGrosConexion.AbrirConexion(gblRutaINI, gblMensajeRPS) < 0Then

'Connection fails

Else

'Connection to database ok

EndIf

EndIf


The function AbrirConexion connects to a SQL Server database and returns a short.
If short is less than 0 the connection is OK
I have read very posts in a lot of forums, but my problem is not resolved.
Anyone cab help me? Sorry from my English
Many, many thanx

Guessing of course - without knowing what's in the functions etc.., but try changing this line
If RPSGrosConexion.AbrirConexion(gblRutaINI, gblMensajeRPS) < 0Then
to
If RPSGrosConexion.AbrirConexion(textbox1.text, gblMensajeRPS) < 0Then
Also , I would use a try block - something like...
Try
Dim MyShort as Short
MyShort =RPSGrosConexion.AbrirConexion(textbox1.text, gblMensajeRPS)
'do other stuff here with open connection - I'm guessing
Catch exc as exception
Finally
'close connection- if the AbrirConexion leaves it open- I don't know
End Try
HTH


Today, when I turn on my computer, the first time I try the code (without your modification), it runs ok. But the next times i have the same error.
The function AbrirConexion open the connection but don't close it.
And I don't know how to close a connection open by a function.
I don't understand it
Help me, please
Well , we can't guess at it...
check out the Reflector tool here ...http://www.aisto.com/roeder/dotnet/
this will aloow you to "see" inside the DLL - it's methods etc..
use that to read through what functions / methods are available. Youwill run the program and tell it to open the DLL for the component yourare trying to use.
Also, can you get support from the authors of this DLL ?
Hope That Helps

OK, I'll try it
Many thanx

System.InvalidCastException: Specified cast is not valid.

Hello All,
Please help. I get the following error from my webpage:
System.InvalidCastException: Specified cast is not valid.
at Time.MaintAtRiskProjects.UpdateProject(String Project, String
AtRiskCode, String Comment)
Code for UpdateProject(String Project, String AtRiskCode, String Comment)
is:
Private Sub UpdateProject(ByVal Project As String, ByVal AtRiskCode As
String, ByVal Comment As String)
Try
Dim strProject As String = Trim(Project)
Dim strAtRiskCode As String = Trim(AtRiskCode)
Dim strComment As String = Trim(Comment)
Dim r As AtRiskProjectsDS.AtRiskProjectsRow
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectColumn
.ColumnName
& "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
strAtRiskCode & "' ")
If rows.Length <> 0 Then
r = rows(0)
If r.Comment <> strComment Then
r.Comment = strComment
End If
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
UpdateProject(ByVal Project As String, ByVal AtRiskCode As String, ByVal
Comment As String) is being called from an update button I have in the page.
The code for Update click is as follows:
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Try
Dim strProject As String = Trim(lblProject.Text)
AtRiskProjDS.Clear()
AtRiskProjDS = LoadAtRiskProjDS(strProject)
For Each item As DataGridItem In dgAtRiskInfo.Items
If item.ItemType = ListItemType.Item Or item.ItemType =
ListItemType.AlternatingItem Then
Dim RiskCodeOld As CheckBox = CType(item.FindControl("chkCodeOld"),
CheckBox)
Dim RiskCodeNew As CheckBox = CType(item.FindControl("chkCodeNew"),
CheckBox)
Dim AtRiskCode As TextBox = CType(item.FindControl("txtAtRiskCode"),
TextBox)
Dim Description As Label = CType(item.FindControl("lblDescription"), Label)
Dim Comment As TextBox = CType(item.FindControl("txtComment"), TextBox)
Dim strAtRiskCode As String = Trim(AtRiskCode.Text)
Dim strDescription As String = Trim(Description.Text)
Dim strComment As String = Trim(Comment.Text)
If RiskCodeOld.Checked = False And RiskCodeNew.Checked = True Then
InsertProject(RiskCodeNew.Checked, strProject, strAtRiskCode,
strDescription, strComment)
RiskCodeOld.Checked = RiskCodeNew.Checked
ElseIf RiskCodeOld.Checked = True And RiskCodeNew.Checked = False Then
DeleteProject(strProject, strAtRiskCode)
RiskCodeOld.Checked = RiskCodeNew.Checked
Else
UpdateProject(strProject, strAtRiskCode, strComment)
End If
End If
Next
SubmitChanges(strProject)
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
Here is what the code for ASPX page looks like:
<%@dotnet.itags.org. Import namespace="Time" %>
<%@dotnet.itags.org. Import namespace="System.Data" %>
<%@dotnet.itags.org. Register TagPrefix="uc1" TagName="footer" src="http://pics.10026.com/?src=../footer.ascx" %>
<%@dotnet.itags.org. Register TagPrefix="uc1" TagName="header" src="http://pics.10026.com/?src=../header.ascx" %>
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="MaintAtRiskProjects.aspx.vb"
Inherits="Time.MaintAtRiskProjects"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MaintAtRiskProjects</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="http://links.10026.com/?link=../master.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="MaintAtRiskProjectsFrm" method="post" runat="server">
<uc1:header id="PageHeader" runat="server"></uc1:header>
<P><asp:dropdownlist id="ddlProject" style="Z-INDEX: 101; LEFT: 16px;
POSITION: absolute; TOP: 72px"
runat="server" OnSelectedIndexChanged="DisplayAtRiskProjInfo"
Font-Names="Lucida Console, Courier New"
Width="168px" autopostback="True"></asp:dropdownlist></P>
<hr style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 104px">
<asp:Button id="btnReport" style="Z-INDEX: 106; LEFT: 504px; POSITION:
absolute; TOP: 64px"
runat="server" Width="97px" Text="View Report"></asp:Button>
<asp:Button id="btnUpdate" style="Z-INDEX: 105; LEFT: 280px; POSITION:
absolute; TOP: 64px"
runat="server" Width="72px" Height="24px"
Text="Update"></asp:Button><asp:label id="lblProject" style="Z-INDEX: 104;
LEFT: 8px; POSITION: absolute; TOP: 128px"
runat="server" Width="160px" ForeColor="#CC0000"
Height="24px"></asp:label><asp:datagrid id="dgAtRiskInfo" style="Z-INDEX:
103; LEFT: 184px; POSITION: absolute; TOP: 128px"
runat="server" Width="385px" Height="160px" ShowFooter="False"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="MistyRose"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<HeaderStyle ForeColor="#CC0000" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtAtRiskCode" Text='<%
#Container.DataItem("AtRiskCode") %>' Runat=server Visible=False>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkCodeOld" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Runat="server" Visible=False>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Check/Uncheck">
<ItemTemplate>
<asp:CheckBox ID="chkCodeNew" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Width="15px" Runat=server>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" text='<%
#Container.DataItem("Description") %>' width="250px" runat=server>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtComment" Text='<% #Container.DataItem("Comment")
%>' Width="400px" Runat=server>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML>
Please help.. Can't figure out what is going on.
Thanks,
Biva
----
--
----
--"Biva" <biva.yauchler@.redprairie.com> wrote in message
news:41dac14e$0$82454$39cecf19@.news.twtelecom.net...
> Hello All,
> Please help. I get the following error from my webpage:
> System.InvalidCastException: Specified cast is not valid.
> at Time.MaintAtRiskProjects.UpdateProject(String Project, String
> AtRiskCode, String Comment)
> Code for UpdateProject(String Project, String AtRiskCode, String Comment)
> is:
...

> Please help.. Can't figure out what is going on.
>
I can't figure out what's going on either, since you did not tell us which
line was causing the error.
This sort of thing happens frequently when a database column contains NULL.
NULL is not a value, so if you try to treat it as a string, you'll get the
invalid cast exception.
John Saunders

John,
My frustration is that it works on my PC that has Framework 1.1.
But when I move it to production that has framework 1.0, it does not
work.
I have the backward compatibility turned on, so it should work.
Since it is on production, i don't have an easy way to debug.
All I could do was set debug=true on web.config and look at the
trace.axd to get that error.
Is there an easy way for me to find out what line is actually giving me
that error?
thanks...
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
"sqlgirl" <sqlgirl@.devdex.com> wrote in message
news:ur12b9n8EHA.1396@.tk2msftngp13.phx.gbl...
>
> John,
> My frustration is that it works on my PC that has Framework 1.1.
> But when I move it to production that has framework 1.0, it does not
> work.
> I have the backward compatibility turned on, so it should work.
> Since it is on production, i don't have an easy way to debug.
> All I could do was set debug=true on web.config and look at the
> trace.axd to get that error.
> Is there an easy way for me to find out what line is actually giving me
> that error?
I don't know, but this kind of thing is a reason to develop on the platform
you're going to use in production.
John Saunders
Here is my DeleteProject method.
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectCo
lumn.ColumnName & "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
strAtRiskCode & "' ")
is the statement that is not being liked for some reason.
Sub DeleteProject(ByVal Project As String, ByVal AtRiskCode As String)
Try
Dim strProject As String = Project
Dim strAtRiskCode As String = AtRiskCode
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectCo
lumn.ColumnName & "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
strAtRiskCode & "' ")
Trace.Write("proj1: " & strProject & ", code1: " &
strAtRiskCode)
Dim r As AtRiskProjectsDS.AtRiskProjectsRow
If rows.Length <> 0 Then
r = rows(0)
r.Delete()
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!
"sqlgirl" <sqlgirl@.devdex.com> wrote in message
news:OuhDdyo8EHA.3592@.TK2MSFTNGP09.phx.gbl...
> Here is my DeleteProject method.
> Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
> AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.AtRiskProjects.ProjectCo
> lumn.ColumnName & "= '" & strProject & "' AND " &
> AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName & "= '" &
> strAtRiskCode & "' ")
Ok, if there's something on that line that ASP.NET doesn't like, then
simplify it:
Dim projectColumnName as String =
AtRiskProjDS.AtRiskProjects.ProjectColumn.ColumnName
Dim atRiskCodeColumnName As String =
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.ColumnName
Dim query As String = projectColumnName & "= '" & strProject & "' AND " &
atRiskCodeColumnName & "= '" & strAtRiskCode & "' "
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(query)
Try that and tell us which line has the problem.
John Saunders
I had defined rows() variable as my dataset.datatablerowtype.
eg.
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow
Framework 1.0 did not like it.
After I changed the rows() variable to simple datarow type as shown
below, it worked fine.
Dim rows() As datarow
Just so if anyone has this problem in the future.
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!

System.InvalidCastException: Specified cast is not valid.

Hi
I get the this error when i run my code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.DataGrid1.DataSource= this.DataSource();
this.DataGrid1.DataBind();
}
private ICollection DataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
for (int i=0;i<10;i++)
{
DataRow dr = dt.NewRow();
if (i%2==0)
{
dr[0]=1;
}
else
{
dr[0]=0;
}
dt.Rows.Add(dr);
}
DataView dv;
dv = new DataView(dt);
return dv;
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
int i = e.Item.ItemIndex;
if(i==0)
{
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
}
}
page:
one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.
It should be pretty easy to step through your code and debug though...
Karl
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>
>

System.InvalidCastException: Specified cast is not valid.

Hi

I get the this error when i run my code:

private void Page_Load(object sender, System.EventArgs e)

{

// Put user code to initialize the page here

this.DataGrid1.DataSource= this.DataSource();

this.DataGrid1.DataBind();

}

private ICollection DataSource()

{

DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));

for (int i=0;i<10;i++)

{

DataRow dr = dt.NewRow();

if (i%2==0)

{

dr[0]=1;

}

else

{

dr[0]=0;

}

dt.Rows.Add(dr);

}

DataView dv;

dv = new DataView(dt);

return dv;

}

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

int i = e.Item.ItemIndex;

if(i==0)

{

((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";

}

}

page:

one two
one two
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
absolute; TOP: 56px" runat="server"
Height="216px" Width="448px" AutoGenerateColumns="False">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:DropDownList ID="dll" Runat="server">
<asp:ListItem Value="0">one</asp:ListItem>
<asp:ListItem Value="1">two</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid
ch JIt would help if you told us the line #. Is it at:
((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";

First of all, it looks like you are doing that when ItemIndex == 0
wouldn't that be ur HeaderTemplate in which case cell[0].Controls[0]. really
might not be what you expect. Secondly, you might prefer
e.Item.FindControl("dll") or e.Item.Cells[0].FindContorl("dll") (not sure
which will work, favor the first one if it'll work) over using indexes. It
makes your code more flexible and less likely to break. Sometimes literals
(like spaces and newlines) are converted to controls, so while you might
think it's Controls[0], it might really be Controls[1] 'cuz there was a
newline before it.

It should be pretty easy to step through your code and debug though...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!

"Jimmy" <beffer@.gmail.com> wrote in message
news:eX0b2r$yFHA.2556@.TK2MSFTNGP10.phx.gbl...
> Hi
> I get the this error when i run my code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> this.DataGrid1.DataSource= this.DataSource();
> this.DataGrid1.DataBind();
> }
> private ICollection DataSource()
> {
> DataTable dt = new DataTable();
>
> dt.Columns.Add(new DataColumn("kol0",typeof(Int16)));
>
> for (int i=0;i<10;i++)
> {
> DataRow dr = dt.NewRow();
> if (i%2==0)
> {
> dr[0]=1;
>
> }
> else
> {
> dr[0]=0;
>
> }
> dt.Rows.Add(dr);
> }
> DataView dv;
> dv = new DataView(dt);
> return dv;
> }
> private void DataGrid1_ItemDataBound(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
> {
> int i = e.Item.ItemIndex;
> if(i==0)
> {
> ((DropDownList)e.Item.Cells[0].Controls[0]).SelectedValue="one";
> }
>
> }
>
> page:
>
> one two
> one two
> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 96px; POSITION:
> absolute; TOP: 56px" runat="server"
> Height="216px" Width="448px" AutoGenerateColumns="False">
> <Columns>
> <asp:TemplateColumn>
> <ItemTemplate>
> <asp:DropDownList ID="dll" Runat="server">
> <asp:ListItem Value="0">one</asp:ListItem>
> <asp:ListItem Value="1">two</asp:ListItem>
> </asp:DropDownList>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
> </asp:DataGrid>
> ch J
>
>

System.InvalidCastException: Specified cast is not valid.

Hello All,
Please help. I get the following error from my webpage:

System.InvalidCastException: Specified cast is not valid.
at Time.MaintAtRiskProjects.UpdateProject(String Project, String
AtRiskCode, String Comment)

Code for UpdateProject(String Project, String AtRiskCode, String Comment)
is:

Private Sub UpdateProject(ByVal Project As String, ByVal AtRiskCode As
String, ByVal Comment As String)

Try

Dim strProject As String = Trim(Project)

Dim strAtRiskCode As String = Trim(AtRiskCode)

Dim strComment As String = Trim(Comment)

Dim r As AtRiskProjectsDS.AtRiskProjectsRow

Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.At RiskProjects.ProjectColumn.ColumnName
& "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.Colum nName & "= '" &
strAtRiskCode & "' ")

If rows.Length <> 0 Then

r = rows(0)

If r.Comment <> strComment Then

r.Comment = strComment

End If

End If

Catch ex As Exception

Trace.Write(ex.ToString)

End Try

End Sub

UpdateProject(ByVal Project As String, ByVal AtRiskCode As String, ByVal
Comment As String) is being called from an update button I have in the page.
The code for Update click is as follows:

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click

Try

Dim strProject As String = Trim(lblProject.Text)

AtRiskProjDS.Clear()

AtRiskProjDS = LoadAtRiskProjDS(strProject)

For Each item As DataGridItem In dgAtRiskInfo.Items

If item.ItemType = ListItemType.Item Or item.ItemType =
ListItemType.AlternatingItem Then

Dim RiskCodeOld As CheckBox = CType(item.FindControl("chkCodeOld"),
CheckBox)

Dim RiskCodeNew As CheckBox = CType(item.FindControl("chkCodeNew"),
CheckBox)

Dim AtRiskCode As TextBox = CType(item.FindControl("txtAtRiskCode"),
TextBox)

Dim Description As Label = CType(item.FindControl("lblDescription"), Label)

Dim Comment As TextBox = CType(item.FindControl("txtComment"), TextBox)

Dim strAtRiskCode As String = Trim(AtRiskCode.Text)

Dim strDescription As String = Trim(Description.Text)

Dim strComment As String = Trim(Comment.Text)

If RiskCodeOld.Checked = False And RiskCodeNew.Checked = True Then

InsertProject(RiskCodeNew.Checked, strProject, strAtRiskCode,
strDescription, strComment)

RiskCodeOld.Checked = RiskCodeNew.Checked

ElseIf RiskCodeOld.Checked = True And RiskCodeNew.Checked = False Then

DeleteProject(strProject, strAtRiskCode)

RiskCodeOld.Checked = RiskCodeNew.Checked

Else

UpdateProject(strProject, strAtRiskCode, strComment)

End If

End If

Next

SubmitChanges(strProject)

Catch ex As Exception

Trace.Write(ex.ToString)

End Try

End Sub

Here is what the code for ASPX page looks like:

<%@dotnet.itags.org. Import namespace="Time" %>
<%@dotnet.itags.org. Import namespace="System.Data" %>
<%@dotnet.itags.org. Register TagPrefix="uc1" TagName="footer" src="http://pics.10026.com/?src=../footer.ascx" %>
<%@dotnet.itags.org. Register TagPrefix="uc1" TagName="header" src="http://pics.10026.com/?src=../header.ascx" %>
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false"
Codebehind="MaintAtRiskProjects.aspx.vb"
Inherits="Time.MaintAtRiskProjects"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>MaintAtRiskProjects</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<LINK href="http://links.10026.com/?link=../master.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="MaintAtRiskProjectsFrm" method="post" runat="server">
<uc1:header id="PageHeader" runat="server"></uc1:header>
<P><asp:dropdownlist id="ddlProject" style="Z-INDEX: 101; LEFT: 16px;
POSITION: absolute; TOP: 72px"
runat="server" OnSelectedIndexChanged="DisplayAtRiskProjInfo"
Font-Names="Lucida Console, Courier New"
Width="168px" autopostback="True"></asp:dropdownlist></P>
<hr style="Z-INDEX: 102; LEFT: 8px; POSITION: absolute; TOP: 104px">
<asp:Button id="btnReport" style="Z-INDEX: 106; LEFT: 504px; POSITION:
absolute; TOP: 64px"
runat="server" Width="97px" Text="View Report"></asp:Button>
<asp:Button id="btnUpdate" style="Z-INDEX: 105; LEFT: 280px; POSITION:
absolute; TOP: 64px"
runat="server" Width="72px" Height="24px"
Text="Update"></asp:Button><asp:label id="lblProject" style="Z-INDEX: 104;
LEFT: 8px; POSITION: absolute; TOP: 128px"
runat="server" Width="160px" ForeColor="#CC0000"
Height="24px"></asp:label><asp:datagrid id="dgAtRiskInfo" style="Z-INDEX:
103; LEFT: 184px; POSITION: absolute; TOP: 128px"
runat="server" Width="385px" Height="160px" ShowFooter="False"
AutoGenerateColumns="False">
<AlternatingItemStyle BackColor="MistyRose"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Right"></ItemStyle>
<HeaderStyle ForeColor="#CC0000" BackColor="Silver"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtAtRiskCode" Text='<%
#Container.DataItem("AtRiskCode") %>' Runat=server Visible=False>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkCodeOld" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Runat="server" Visible=False>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Check/Uncheck">
<ItemTemplate>
<asp:CheckBox ID="chkCodeNew" Checked='<%
#Container.DataItem("RiskCodeFlag") %>' Width="15px" Runat=server>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblDescription" text='<%
#Container.DataItem("Description") %>' width="250px" runat=server>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Comment">
<ItemTemplate>
<asp:TextBox ID="txtComment" Text='<% #Container.DataItem("Comment")
%>' Width="400px" Runat=server>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
</HTML
Please help.. Can't figure out what is going on.

Thanks,

Biva

------------------------

------------------------"Biva" <biva.yauchler@.redprairie.com> wrote in message
news:41dac14e$0$82454$39cecf19@.news.twtelecom.net. ..
> Hello All,
> Please help. I get the following error from my webpage:
> System.InvalidCastException: Specified cast is not valid.
> at Time.MaintAtRiskProjects.UpdateProject(String Project, String
> AtRiskCode, String Comment)
> Code for UpdateProject(String Project, String AtRiskCode, String Comment)
> is:

...

> Please help.. Can't figure out what is going on.

I can't figure out what's going on either, since you did not tell us which
line was causing the error.

This sort of thing happens frequently when a database column contains NULL.
NULL is not a value, so if you try to treat it as a string, you'll get the
invalid cast exception.

John Saunders

John,
My frustration is that it works on my PC that has Framework 1.1.
But when I move it to production that has framework 1.0, it does not
work.
I have the backward compatibility turned on, so it should work.
Since it is on production, i don't have an easy way to debug.
All I could do was set debug=true on web.config and look at the
trace.axd to get that error.
Is there an easy way for me to find out what line is actually giving me
that error?

thanks...

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"sqlgirl" <sqlgirl@.devdex.com> wrote in message
news:ur12b9n8EHA.1396@.tk2msftngp13.phx.gbl...
>
> John,
> My frustration is that it works on my PC that has Framework 1.1.
> But when I move it to production that has framework 1.0, it does not
> work.
> I have the backward compatibility turned on, so it should work.
> Since it is on production, i don't have an easy way to debug.
> All I could do was set debug=true on web.config and look at the
> trace.axd to get that error.
> Is there an easy way for me to find out what line is actually giving me
> that error?

I don't know, but this kind of thing is a reason to develop on the platform
you're going to use in production.

John Saunders
Here is my DeleteProject method.
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.At RiskProjects.ProjectCo
lumn.ColumnName & "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.Colum nName & "= '" &
strAtRiskCode & "' ")

is the statement that is not being liked for some reason.

Sub DeleteProject(ByVal Project As String, ByVal AtRiskCode As String)

Try
Dim strProject As String = Project
Dim strAtRiskCode As String = AtRiskCode

Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.At RiskProjects.ProjectCo
lumn.ColumnName & "= '" & strProject & "' AND " &
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.Colum nName & "= '" &
strAtRiskCode & "' ")
Trace.Write("proj1: " & strProject & ", code1: " &
strAtRiskCode)
Dim r As AtRiskProjectsDS.AtRiskProjectsRow

If rows.Length <> 0 Then
r = rows(0)
r.Delete()
End If
Catch ex As Exception
Trace.Write(ex.ToString)
End Try
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"sqlgirl" <sqlgirl@.devdex.com> wrote in message
news:OuhDdyo8EHA.3592@.TK2MSFTNGP09.phx.gbl...
> Here is my DeleteProject method.
> Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
> AtRiskProjDS.AtRiskProjects.Select(AtRiskProjDS.At RiskProjects.ProjectCo
> lumn.ColumnName & "= '" & strProject & "' AND " &
> AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.Colum nName & "= '" &
> strAtRiskCode & "' ")

Ok, if there's something on that line that ASP.NET doesn't like, then
simplify it:

Dim projectColumnName as String =
AtRiskProjDS.AtRiskProjects.ProjectColumn.ColumnNa me
Dim atRiskCodeColumnName As String =
AtRiskProjDS.AtRiskProjects.AtRiskCodeColumn.Colum nName
Dim query As String = projectColumnName & "= '" & strProject & "' AND " &
atRiskCodeColumnName & "= '" & strAtRiskCode & "' "
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow =
AtRiskProjDS.AtRiskProjects.Select(query)

Try that and tell us which line has the problem.

John Saunders
I had defined rows() variable as my dataset.datatablerowtype.
eg.
Dim rows() As AtRiskProjectsDS.AtRiskProjectsRow

Framework 1.0 did not like it.

After I changed the rows() variable to simple datarow type as shown
below, it worked fine.

Dim rows() As datarow

Just so if anyone has this problem in the future.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Wednesday, March 28, 2012

System.InvalidOperationException: Collection was modified; enumeration operation may not e

hi all,

i am getting the following error when i am trying to move the ltems form listbox1 to listbox2

"System.InvalidOperationException: Collection was modified; enumeration operation may not execute"

ForEach itemAs ListItemIn Listbox1.Items

If item.SelectedAndNot Listbox2.Items.Contains(item)Then

Dim newItemAsNew ListItem(item.Text, item.Value)

Listbox2.Items.Add(newItem)

listbox1.Remove(newitem)

EndIf

Next

thanks.

You can't modify the listbox1 item collection while you are iterating over it using "for each". Wait until you add everything to listbox2, and then call Clear() on listbox1.

System.InvalidOperationException: Timeout expired when calling a ASP.NET service

I get this error when calling an ASP.NET service. Any idea what this is and how to prevent it?

System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.

This probably means that your service is leaking database connections. You must Dispose() (or Close()) all resources that implement the IDisposable interface, which includes such things as SqlConnection etc. The best way to ensure this is usually to enclose the usage in a 'using'-statement. Check out the text and example here:http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection(vs.80).aspx .
Well I do see someone put recycle threads at 1740 minutes...which is normally 20minutes. Do you think that could cause the problem?

No. That's not the problem. If you're leaking connections you must fix that. The default recycle is set at 1740 iirc for IIS 6, not 20 minutes. You do not want to recycle every 20 minutes! That's like getting a bigger bucket to scoop out the water of your boat instead of fixing the holes. It'll work for a time, but sooner or later you'll sink anyway.

Fix the code.


I can see where the SQL connections were not closed. So I added the close code as well. But these are one time hits to a service so I see no reason why the worker processes could not be recycled sooner and save on any memory of any "hung" threads.

If you have hung threads you should ensure that they do not hang. Killing the entire worker process is sort of like than swatting flies with a sledgehammer, you'll mostly miss and in most cases cause more harm in the process of trying than was originally caused by the problem. (This seems to be my day for analogies... ;-) Depending on process recycling to fix problems that should be fixed in code is, well, just simply bad. In the best case you'll have less performance than you'd get otherwise (this may not be a concern by itself, if you have capacity to spare but...) in the worst case, which is the common case, you'll get an unstable site that sometimes works, and sometimes do not. Also - if you're using sessions stored in process, the users will loose these sessions at the time of the recycle - in effect, every 20 minutes all the currently active users will loose their session. That's not so good.

If you have anything cached - you loose it. You'll have to reload the entire AppDomain. All in all - worker process recycling is pretty costly. Don't use it as a way to hide the bugs in your code!

You should engineer your site to be able to run forever. You may for example check this link:http://www.asp.net/faq/AspNetAndIIS6.aspx - note that automatic process recycling is not recommended! (There are some various views on this subject, but you'll find no-one recommending it every 20 minutes for any reason!)

Reactive process recycling, i.e. as a response to an error condition, is ok since it increases the application up-time - but should always be accompanied by an alarm, so that the root cause can be eliminated.


I just talked with the guy that wrote the code causing the problem as I still close connections and try and manage memory like an old ASP programmer. But he and I attended classes on asp.net where Microsoft reps told us there is no need to close SQL connections or do any of this stuff as asp.net as automatic garbage collection and automatically cleans itself up from all of this.

But what this shows is, we are right back to the point where a users bad code can take down the entire web server...not a great feeling.


Don't know what the Microsoft reps were taking, but unfortunately they were wrong and you are right in more ways than one.

Garbage collection does remove the risk for memory leaks, unfortunately it introduces the twofold problems of indeterminite response time (you can't know when a garbage collection may be required, thus cannot guarantee a minimum response time which makes the whole platform more or less useless for anything approaching real-time scenarios) and memory fragmentation in the large object heap in the end leading to out of memory conditions (one of the few reasons you may in fact have to recycle).

Garbage collection does not solve the problem of unmanaged resources, nor does it solve the problem of untimely shortage of some resources. The database pool connections will in fact be reclaimed at some point by garbage collection, but shortage of such a resource does not trigger a forced gc to that will ensure any loose ones to be reclaimed - causing the effects you noted.

So - If an object implements IDisposable, you're stuck with managing it and ensuring it's timely disposal just like in the old days. But there is the nice 'using' statement to help you with that chore... ;-)

System.IO.File.Copy not copying and no error

I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then
throw a new exception, outputing your source/destination paths along with
the original exception:

Try
System.IO.File.Copy(Source,Dest)
Catch ex as exception
throw new Exception("Source: '" & source & "' - Dest: '" & dest &
"'",ex)
end try

also, put a break point at the Throw, and examine your variables.

"Xander Q." <xander_q@dotnet.itags.org.hotmail.com> wrote in message
news:1958ff15.0307052341.260d3083@dotnet.itags.org.posting.google.c om...
> Something really strange is happening. i'm using the following code to
> copy a file. this worked on my development machine, but when i moved
> it to the server (win2k) it is not copying the file and not generating
> an error. it just merrily goes on.
> ---------------------
> source= Server.MapPath("/TTClaimsForm2/Reports/xxx.doc")
> dest= Server.MapPath("/TTClaimsForm2/Reports/Temp/xxx.doc")
> System.IO.File.Copy(source, dest)
> ---------------------
>
> i checked the value of dest and it's correct. i replaced it with an
> empty string and it gave an error as expected.
> BUT i noticed that if i hard code destination like this:
> System.IO.File.Copy(source,
> "C:\inetpub\wwwroot\ttclaimsform2\Temp\xxx.doc") then the copy works.
> how can this be happening?"David Waz..." <dlw@.pickpro.com> wrote in message news:<bhZNa.1682$Ro2.1449@.newssvr31.news.prodigy.com>...
> I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then
> throw a new exception, outputing your source/destination paths along with
> the original exception:

ah yes i neglected to mention that i already did that, and the value
of 'dest' is correct. it is the same as the hard-coded string and yet
it fails...

damn i hate this stuff!!!

but thx for the input...

System.IO.FileNotFoundException help

Not sure where this error is coming from. I have my asp.net app set to email
me error messages, but this error message does not indicate where it occurs.
There is no page called get_aspx_ver.aspx and I don't know where it's
getting that. Any ideas?
System.IO.FileNotFoundException:
c:\inetpub\wwwroot\framescale\get_aspx_v
er.aspx
at System.Web.UI.TemplateParser.GetParserCacheItem()
at System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
virtualPath, String inputFile, HttpContext context)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String
requestType, String url, String path)
at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
requestType, String path, String pathTranslated, Boolean useAppConfig)"When you try to open an ASP.NET Web Application project, the ASP.NET
process accesses a nonexistent file that is named Get_aspx_ver.aspx to
retrieve the ASP.NET version information. If the defaultRedirect attribute
is not set to an HTML file or to an ASP file, the request for the
Get_aspx_ver.aspx file returns the HTTP 404 error and the ASP.NET version
information. If the defaultRedirect attribute is set to an HTML file or to
an ASP file, the request for the Get_aspx_ver.aspx file does not return the
ASP.NET version information. Therefore, you receive the error that is
mentioned in the "Symptoms" section of this article. "
http://support.microsoft.com/defaul...kb;en-us;825792
Also:
http://bluebones.net/news/default.a...ory&story_id=50
"msnews.microsoft.com" <maximus@.portvista.com> wrote in message
news:%23B6kthPSEHA.3944@.TK2MSFTNGP11.phx.gbl...
> Not sure where this error is coming from. I have my asp.net app set to
> email
> me error messages, but this error message does not indicate where it
> occurs.
> There is no page called get_aspx_ver.aspx and I don't know where it's
> getting that. Any ideas?
> System.IO.FileNotFoundException:
> c:\inetpub\wwwroot\framescale\get_aspx_v
er.aspx
> at System.Web.UI.TemplateParser.GetParserCacheItem()
> at System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.TemplateControlParser.GetCompiledInstance(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
> virtualPath, String inputFile, HttpContext context)
> at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String
> requestType, String url, String path)
> at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
> requestType, String path, String pathTranslated, Boolean useAppConfig)
>
Nice going Microsoft. I'd not being wearing that MVP badge so proudly! lol!
"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:e1ie4XQSEHA.568@.TK2MSFTNGP12.phx.gbl...
> "When you try to open an ASP.NET Web Application project, the ASP.NET
> process accesses a nonexistent file that is named Get_aspx_ver.aspx to
> retrieve the ASP.NET version information. If the defaultRedirect attribute
> is not set to an HTML file or to an ASP file, the request for the
> Get_aspx_ver.aspx file returns the HTTP 404 error and the ASP.NET version
> information. If the defaultRedirect attribute is set to an HTML file or to
> an ASP file, the request for the Get_aspx_ver.aspx file does not return
the
> ASP.NET version information. Therefore, you receive the error that is
> mentioned in the "Symptoms" section of this article. "