Saturday, March 31, 2012
System.FormatException: Index (zero based) must be greater than or equal to zero
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.InvalidCastException: Specified cast is not valid.
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.
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
>
>
Wednesday, March 28, 2012
System.IO.Directory.GetFiles(path, searchPattern)
Hi
I don't know if this is the right place to put this post but I didn't found anywhere else.
The thing is that I'm getting files in a directory but I would like to pick only four types of files: .wmv, .avi, .mpeg and .mpg. I know that the search pattern works but I can only search for one type of file. Can extend the search to look for all 4 types?
Thx
It seems that there is no direct way to do this, really strange. Maybe you can get all files under the directory, and then use regular expression to get files of these types?Hi
Thx for the reply. I already thought of that. I know it works cause I tried it. I just wanted another way to optimize unnecessary code. But thanks anyway lori_Jay
system.IO.File.Exists doesnt working for file that is outside my virtual directory
i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no
if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.
so how to select file from any folder on my PC and chech that it exist
or notIt may have to do with the ASP.net user in IIS not having read
permissions on the directories?
Max wrote:
Quote:
Originally Posted by
hi
>
i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no
>
if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.
>
so how to select file from any folder on my PC and chech that it exist
or not
Are you using an absolute path or a relative path to the file?
"Max" wrote:
Quote:
Originally Posted by
hi
>
i have file browser control to select any file and a button to upload
file on my web page now when i select any file. now on click of upload
button i have check that file exist or no
>
if system.IO.File.Exist(file path) then
...
end if
now when ever i choose file system.IO.File.Exist(file path) return
false, but if i select file from my virtual directory then only it
return true.
>
so how to select file from any folder on my PC and chech that it exist
or not
>
>
followin is the error i am getting
Server Error in '/' Application.
------------------------
Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg"
is denied.
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
Stack Trace:
[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
What do you not understand about the exception's explanation?
--
HTH,
Kevin Spencer
Microsoft MVP
Chicken Salad Surgery
Orange you bland I stopped splaying bananas?
"Max" <mahesh.anjani@.gmail.comwrote in message
news:1155306880.304856.71550@.i3g2000cwc.googlegrou ps.com...
Quote:
Originally Posted by
followin is the error i am getting
>
Server Error in '/' Application.
------------------------
>
Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
>
Exception Details: System.UnauthorizedAccessException: Access to the
path "L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg"
is denied.
>
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS
5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user
(typically IUSR_MACHINENAME) or the authenticated request user.
>
To grant ASP.NET write access to a file, right-click the file in
Explorer, choose "Properties" and select the Security tab. Click "Add"
to add the appropriate user or group. Highlight the ASP.NET account,
and check the boxes for the desired access.
>
Source Error:
>
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of
the exception can be identified using the exception stack trace below.
>
>
Stack Trace:
>
>
[UnauthorizedAccessException: Access to the path
"L:\Webhosting\home.gujarat.gov.in\homeapps\imagefi les\images.jpg" is
denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.File.Delete(String path) +165
CMSAPPS.mas_WMKD_entry.Save_ADD() in
D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :248
CMSAPPS.mas_WMKD_entry.bttn_Save_Click(Object sender, EventArgs e)
in D:\dnSource\HOMEAPPS_mahesh\mas_WMKD_entry.aspx.vb :221
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
>
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292
>
Monday, March 26, 2012
System.Net.Dns.GetHostByAddress returns incorrec t Hostame
I have a problem with
System.Net.Dns.GetHostByAddress(ls_Request.UserHos tAddress()).HostName
Usually the call GetHostByAddress returns the correct hostname of the
client, but sometimes I get a hostname like _CERDR1342B88E.
Why? The clients are running under Windows CE.NET 4.1...
SvenSven wrote:
> Hi!
> I have a problem with
> System.Net.Dns.GetHostByAddress(ls_Request.UserHos tAddress()).HostName
> Usually the call GetHostByAddress returns the correct hostname of the
> client, but sometimes I get a hostname like _CERDR1342B88E.
> Why? The clients are running under Windows CE.NET 4.1...
> Sven
What happens if you probe a ip address that returns such a name op port 445?
Is it open? If so, the computername is returned and not the hostname.
Someone with more knowledge of the tcp/ip system could clear this out.
//Rutger
You should post this to the
microsoft.public.dotnet.framework.compactframework group.
feroze
==============
this posting is provided as-is.
"Rutger Smit" <DoDotNet@.gmail.com> wrote in message
news:10jf0rcdh7os851@.corp.supernews.com...
> Sven wrote:
> > Hi!
> > I have a problem with
> > System.Net.Dns.GetHostByAddress(ls_Request.UserHos tAddress()).HostName
> > Usually the call GetHostByAddress returns the correct hostname of the
> > client, but sometimes I get a hostname like _CERDR1342B88E.
> > Why? The clients are running under Windows CE.NET 4.1...
> > Sven
> What happens if you probe a ip address that returns such a name op port
445?
> Is it open? If so, the computername is returned and not the hostname.
> Someone with more knowledge of the tcp/ip system could clear this out.
> //Rutger
Well, the call System.Net.Dns.GetHostByAddress is executed on a
Windows 2003 Server... and i want to get the hostname of an IP address
(from a Windows CE system). I don't know if the behaviour is specific
to CE...
"Feroze [msft]" <ferozed@.online.microsoft.com> wrote in message news:<413795eb$1@.news.microsoft.com>...
> You should post this to the
> microsoft.public.dotnet.framework.compactframework group.
> feroze
> ==============
> this posting is provided as-is.
Rutger Smit <DoDotNet@.gmail.com> wrote in message news:<10jf0rcdh7os851@.corp.supernews.com>...
> Sven wrote:
> > Hi!
> > I have a problem with
> > System.Net.Dns.GetHostByAddress(ls_Request.UserHos tAddress()).HostName
> > Usually the call GetHostByAddress returns the correct hostname of the
> > client, but sometimes I get a hostname like _CERDR1342B88E.
> > Why? The clients are running under Windows CE.NET 4.1...
> > Sven
> What happens if you probe a ip address that returns such a name op port 445?
> Is it open? If so, the computername is returned and not the hostname.
> Someone with more knowledge of the tcp/ip system could clear this out.
> //Rutger
I looked up the computername on the windows ce machines, but the
computername is the one we set initialy (not _CERDR1342B88E)! But the
call System.Net.Dns.GetHostByAddress returns _CERDR1342B88E. I don't
know what the call System.Net.Dns.GetHostByAddress exactly does, but
it does not seem to be right.
Since the hostname is not really _CERDR1342B88E, i think a probe on
port 445 does not make sense...
Sven
Sven wrote:
> Rutger Smit <DoDotNet@.gmail.com> wrote in message news:<10jf0rcdh7os851@.corp.supernews.com>...
>
> I looked up the computername on the windows ce machines, but the
> computername is the one we set initialy (not _CERDR1342B88E)! But the
> call System.Net.Dns.GetHostByAddress returns _CERDR1342B88E. I don't
> know what the call System.Net.Dns.GetHostByAddress exactly does, but
> it does not seem to be right.
> Since the hostname is not really _CERDR1342B88E, i think a probe on
> port 445 does not make sense...
> Sven
It looks like GetHostByAddress does NOT always do a reverse lookup. Ik
don't know what is doe. Try to analyze the network logs that can be
caputred using Ethereal.
The port 445 suggestion was becaus of the computername, but it doens't
have anything to do with it.
//Rutger
System.Net.Dns.GetHostByAddress returns incorrec t Hostame
I have a problem with
System.Net.Dns.GetHostByAddress(ls_Request.UserHostAddress()).HostName
Usually the call GetHostByAddress returns the correct hostname of the
client, but sometimes I get a hostname like _CERDR1342B88E.
Why? The clients are running under Windows CE.NET 4.1...
SvenSven wrote:
> Hi!
> I have a problem with
> System.Net.Dns.GetHostByAddress(ls_Request.UserHostAddress()).HostName
> Usually the call GetHostByAddress returns the correct hostname of the
> client, but sometimes I get a hostname like _CERDR1342B88E.
> Why? The clients are running under Windows CE.NET 4.1...
> Sven
What happens if you probe a ip address that returns such a name op port 445?
Is it open? If so, the computername is returned and not the hostname.
Someone with more knowledge of the tcp/ip system could clear this out.
//Rutger
You should post this to the
microsoft.public.dotnet.framework.compactframework group.
feroze
==============
this posting is provided as-is.
"Rutger Smit" <DoDotNet@.gmail.com> wrote in message
news:10jf0rcdh7os851@.corp.supernews.com...
> Sven wrote:
>
> What happens if you probe a ip address that returns such a name op port
445?
> Is it open? If so, the computername is returned and not the hostname.
> Someone with more knowledge of the tcp/ip system could clear this out.
> //Rutger
Well, the call System.Net.Dns.GetHostByAddress is executed on a
Windows 2003 Server... and i want to get the hostname of an IP address
(from a Windows CE system). I don't know if the behaviour is specific
to CE...
"Feroze [msft]" <ferozed@.online.microsoft.com> wrote in message news:<413795eb$1@.news.microsoft.c
om>...
> You should post this to the
> microsoft.public.dotnet.framework.compactframework group.
> feroze
> ==============
> this posting is provided as-is.
Rutger Smit <DoDotNet@.gmail.com> wrote in message news:<10jf0rcdh7os851@.corp.supernews.com>
..
> Sven wrote:
>
> What happens if you probe a ip address that returns such a name op port 44
5?
> Is it open? If so, the computername is returned and not the hostname.
> Someone with more knowledge of the tcp/ip system could clear this out.
> //Rutger
I looked up the computername on the windows ce machines, but the
computername is the one we set initialy (not _CERDR1342B88E)! But the
call System.Net.Dns.GetHostByAddress returns _CERDR1342B88E. I don't
know what the call System.Net.Dns.GetHostByAddress exactly does, but
it does not seem to be right.
Since the hostname is not really _CERDR1342B88E, i think a probe on
port 445 does not make sense...
Sven
Sven wrote:
> Rutger Smit <DoDotNet@.gmail.com> wrote in message news:<10jf0rcdh7os851@.co
rp.supernews.com>...
>
> I looked up the computername on the windows ce machines, but the
> computername is the one we set initialy (not _CERDR1342B88E)! But the
> call System.Net.Dns.GetHostByAddress returns _CERDR1342B88E. I don't
> know what the call System.Net.Dns.GetHostByAddress exactly does, but
> it does not seem to be right.
> Since the hostname is not really _CERDR1342B88E, i think a probe on
> port 445 does not make sense...
> Sven
It looks like GetHostByAddress does NOT always do a reverse lookup. Ik
don't know what is doe. Try to analyze the network logs that can be
caputred using Ethereal.
The port 445 suggestion was becaus of the computername, but it doens't
have anything to do with it.
//Rutger
system.net.mail question
Hi
I am using system.net.mail to generate an E-mail from my form. When I recieve the message the header shows
I am trying to determine if the MIME is getting added from the source server that is sending our email or the server where we retrieve our email from. Or can this be controled by system.net.mail? Any help is appreciated.
Robby
I don't know - but I use this place as a referencehttp://systemnetmail.com/
Saturday, March 24, 2012
System.Net.WebException: The remote server returned an error: (500) Internal Server Error.
I am trying to consume a web service from asp.net web page through
HTTP POST method and I am getting the following error message
"System.Net.WebException: The remote server returned an error: (500)
Internal Server Error."
I have been searchign the web and followed all the options which worked
for others
1. Changed the web.config of the web service to accomodate HttpPost
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices
2. Used the HttpRequest.Credentials =
CredentialCache.DefaultCredentials;
I am not sure what is wrong there it fails while the request is sent to
the web service. The web service works fine with other web clients
Let me know your ideas
thanks
MohanOther web clients? What is different? Run the debugger on the server,
set a breakpoint and POST from your client, and step through the code
sirfunusa wrote:
> Other web clients? What is different? Run the debugger on the server,
> set a breakpoint and POST from your client, and step through the code
Other clients I mean when I reference the web service and access the
web method it works fine...But when I use an ASP.NET page with the
HTTPReuest Object as shown below it throws the error
"System.Net.WebException: The remote server returned an error: (500)
Internal Server Error."
Code :
HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://localhost//SubtractNumbers//Service1.asmx//Subtract");
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
//wr.ContentLength = bytes.Length;
StreamWriter writer = new
StreamWriter(wr.GetRequestStream(),System.Text.Enc oding.UTF8);
//// Write the xml text into the stream
writer.WriteLine("Hi");
writer.Close();
WebResponse wrs = wr.GetResponse();
Stream strm = wrs.GetResponseStream();
StreamReader sr = new StreamReader(strm);
String line;
while( (line = sr.ReadLine()) != null)
Response.Write(line);
strm.Close();
sirfunusa wrote:
> Other web clients? What is different? Run the debugger on the server,
> set a breakpoint and POST from your client, and step through the code
Other clients I mean when I reference the web service and access the
web method it works fine...But when I use an ASP.NET page with the
HTTPReuest Object as shown below it throws the error
"System.Net.WebException: The remote server returned an error: (500)
Internal Server Error."
Code :
HttpWebRequest wr =
(HttpWebRequest)WebRequest.Create("http://localhost//SubtractNumbers//Service1.asmx//Subtract");
wr.Method = "POST";
wr.ContentType = "application/x-www-form-urlencoded";
//wr.ContentLength = bytes.Length;
StreamWriter writer = new
StreamWriter(wr.GetRequestStream(),System.Text.Enc oding.UTF8);
//// Write the xml text into the stream
writer.WriteLine("Hi");
writer.Close();
WebResponse wrs = wr.GetResponse();
Stream strm = wrs.GetResponseStream();
StreamReader sr = new StreamReader(strm);
String line;
while( (line = sr.ReadLine()) != null)
Response.Write(line);
strm.Close();
Are you sending the proper XML message (SOAP)? If your message isn't
formatted properly, you will definately get a server 500 error back.
It looks liek you are actually just sending text ("Hi"). That's not a
proper SOAP message. Here is a sample of a SOAP message:
http://www.w3.org/2004/06/03-google-soap-wsdl.html .
I personally much of web services manually because it's just easier to
interop with COM that way.
Here's part of what I do... (also be sure to set your SOAPAction in the
http header!) messageData hold my XML message I'm sending.
ASCIIEncoding encoding = new ASCIIEncoding( );
byte[] buffer = encoding.GetBytes(messageData);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(this.EndPoint);
myRequest.Method = "POST";
myRequest.ContentType = "text/xml";
myRequest.ContentLength = buffer.Length;
myRequest.Headers.Add(String.Format("SOAPAction: \"{0}\"",
operationName));
myRequest.Timeout = 10000;
using (Stream newStream = myRequest.GetRequestStream( )) {
newStream.Write(buffer, 0, buffer.Length);
newStream.Close( );
}
HttpWebResponse myHttpWebResponse =
(HttpWebResponse)myRequest.GetResponse( );
string rawResponse =
GetWebResponseString(myHttpWebResponse);
myHttpWebResponse.Close( );
Here is the GetWebResponseString method...
private static string GetWebResponseString(WebResponse
myHttpWebResponse) {
StringBuilder rawResponse = new StringBuilder( );
using (Stream streamResponse =
myHttpWebResponse.GetResponseStream( )) {
using (StreamReader streamRead = new
StreamReader(streamResponse)) {
Char[] readBuffer = new Char[256];
int count = streamRead.Read(readBuffer, 0, 256);
while (count > 0) {
String resultData = new String(readBuffer, 0,
count);
rawResponse.Append(resultData);
count = streamRead.Read(readBuffer, 0, 256);
}
}
}
return rawResponse.ToString( );
}
Look closely at what is returned. You may actually be getting the
reason for the fault in the message.
Also, if all is successful, you will get an XML message back. Are you
prepared to parse it?
You may want to actually use the .NET web service mechanism if you
don't want to do everything manually. Since you aren't using the .NET
web service mechanism the web.config configuration doesn't apply.
If you are intending to use .NET for web services, then all you have to
do is add the WSDL file as a web reference and use it as though it were
local. There's not really much work to it. If that is the case then
everything I said above is void, since this is the manual way to do it.
System.NullReferenceException
I try to use this piece of code...
Dim CatID As Integer
CatID = (Request.QueryString("ID"))
CatID = 1
myProductsByCategory.Text = (GetProductsByCategory(CatID))
inside my Private Sub Page_Load but I get a System.NullReferenceException error from this.
What am I missing here?
Regards
MMy guess would be that the Querystring "ID" doesnt exist and you are getting a NULL exception when VB is converting it to an integer.
I hit Post too soon.. you might want to try to comment out the line that is assigning the value from the Querystring, since you are hardcoding it anyway (to 1).. see if thats the issue.
Hi
I comment out the querystring part, but that didn't help...
Regards
M
By the way... the function I try to call looks like this..
Function GetProductsByCategory(ByVal intID As Integer)
Dim connStr As String
connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")Dim sb As StringBuilder = New StringBuilder
Dim sbOutput As StringDim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyDataReader As SqlDataReaderMyConnection = New SqlConnection(connStr)
Try
MyConnection.Open()
MyCommand = New SqlCommand("dbo.p_ShowProductsByCategories", MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Parameters.Add("@.ID", SqlDbType.Int, 4).Value = intID
MyDataReader = MyCommand.ExecuteReader()sb.Append("<table width=""123"" border=""0"" cellpadding=""0"" cellspacing=""0"">")
While MyDataReader.Read
sb.Append("<tr>")
sb.Append("<td class=""menuitem"" onmouseover=""this.bgColor='#EEEEEE'"" onmouseout=""this.bgColor='#FDFDFD'"" style=""HEIGHT: 16px""> <a ref=""productdetail.aspx?ID=""" & (MyDataReader("ID")) & """>" & (MyDataReader("Description")) & "</a></td>" & vbCrLf)
sb.Append("</tr>")
End Whilesb.Append("</table>")
sbOutput = sb.ToString()
MyDataReader.Close()
MyConnection.Close()Catch ex As Exception
myErrorCode.Visible = True
myErrorCode.Text = (" ! An error occured <br> while accesing<br> products")
'Response.Write(ex.Message.ToString)
End Try
GetProductsByCategory = sbOutput
End Function
Regards
M
Ok.. is the runtime error not giving you the line number of the error? Are you sure the error is happening in those original 4 lines of code posted?
Try setting a breakpoint on the offending line and stepping through the GetProductsByCategory method to see where the problem lies.
(If you don't have Visual Studio you can use the CLR debugger in the .net framework SDK. You'll find it at
C:\Program Files\Microsoft.NET\FrameworkSDK\GuiDebug\DbgCLR.exe
You'll need to attach it to the aspnet_wp.exe process first. Choose "Debug Processes..." on the "Tools" menu, select aspnet_wp.exe and click "Attach".)
You are right, sorry! The line where the error is ...
myProductsByCategory.Text = (GetProductsByCategory(1))
Regards
M
Ok.. best case, your myProductsByCategory.Text is the problem.. worse case its a problem in the function, which is most likely the problem :)
connStr = ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_connStr")
Are yousure that you have this entry in your web.config file?
Yes I have, I use that part in the sub page_load so I know thats working.
Regards
M
Time to step through your code and see whats up then :)
Hmmm... I found the problem, I have forgotten to add the runat=server to the label holding the result.
Regards
M
Thursday, March 22, 2012
System.OutofMemoryException - Session
I have an application running on a cluster that's constantly throwing an OutOfMemoryException with the following message
"Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'.
In this instance, session state mode is set to 'StateServer' and the only object being stored in the session is a dataset (which is serializable)..
Anyone have any ideas
Thanks!for starters, what does your dataset contain?
any funky stuff in the dataset or just basic types?
i'm puzzled that an outofmemoryexception would contain a serialization
string
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Fletch" <anonymous@.discussions.microsoft.com> wrote in message
news:0F2E1CFD-71B2-41BA-9874-1AD07F3BDB5A@.microsoft.com...
> Hi,
> I have an application running on a cluster that's constantly throwing an
OutOfMemoryException with the following message:
> "Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'."
> In this instance, session state mode is set to 'StateServer' and the only
object being stored in the session is a dataset (which is serializable)..
> Anyone have any ideas?
> Thanks!
for starters, what does your dataset contain?
any funky stuff in the dataset or just basic types?
i'm puzzled that an outofmemoryexception would contain a serialization
string
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Fletch" <anonymous@.discussions.microsoft.com> wrote in message
news:0F2E1CFD-71B2-41BA-9874-1AD07F3BDB5A@.microsoft.com...
> Hi,
> I have an application running on a cluster that's constantly throwing an
OutOfMemoryException with the following message:
> "Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'."
> In this instance, session state mode is set to 'StateServer' and the only
object being stored in the session is a dataset (which is serializable)..
> Anyone have any ideas?
> Thanks!
System.OutofMemoryException - Session
I have an application running on a cluster that's constantly throwing an OutOfMemoryException with the following message
"Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'.
In this instance, session state mode is set to 'StateServer' and the only object being stored in the session is a dataset (which is serializable)..
Anyone have any ideas
Thanks!for starters, what does your dataset contain?
any funky stuff in the dataset or just basic types?
i'm puzzled that an outofmemoryexception would contain a serialization
string
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Fletch" <anonymous@.discussions.microsoft.com> wrote in message
news:0F2E1CFD-71B2-41BA-9874-1AD07F3BDB5A@.microsoft.com...
> Hi,
> I have an application running on a cluster that's constantly throwing an
OutOfMemoryException with the following message:
> "Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'."
> In this instance, session state mode is set to 'StateServer' and the only
object being stored in the session is a dataset (which is serializable)..
> Anyone have any ideas?
> Thanks!
System.OutofMemoryException - Session
I have an application running on a cluster that's constantly throwing an OutOfMemoryException with the following message
"Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'.
In this instance, session state mode is set to 'StateServer' and the only object being stored in the session is a dataset (which is serializable)..
Anyone have any ideas
Thanks!for starters, what does your dataset contain?
any funky stuff in the dataset or just basic types?
i'm puzzled that an outofmemoryexception would contain a serialization
string
--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Fletch" <anonymous@.discussions.microsoft.com> wrote in message
news:0F2E1CFD-71B2-41BA-9874-1AD07F3BDB5A@.microsoft.com...
> Hi,
> I have an application running on a cluster that's constantly throwing an
OutOfMemoryException with the following message:
> "Unable to serialize the session state. Please note that non-serializable
objects or MarshalByRef objects are not permitted when session state mode is
'StateServer' or 'SQLServer'."
> In this instance, session state mode is set to 'StateServer' and the only
object being stored in the session is a dataset (which is serializable)..
> Anyone have any ideas?
> Thanks!