473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

webservice questions

Hi all,
I'm new to asp.net and are just working on a few examples to get some
practice. The following is a simple webservice with two web methods. The
HowMuchWillItCost method works fine the GetProductInfo method returns http
500 internal server error. Maybe someone could tell me what am I doing
wrong?
I suspect it has something to do with connecting to the DB but can't figure
out what exactly is causing the error.
TIA
Rich

[WebMethod]
public decimal HowMuchWillItCost(string productName, int howMany)
{
try
{
OleDbConnection oleDbConn = new OleDbConnection ("Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand();
oleDbCmd.CommandText = "SELECT UnitPrice FROM Products WHERE ProductName =
'" + productName + "'";
oleDbCmd.Connection = oleDbConn;
oleDbConn.Open ();
decimal price = (decimal)oleDbCmd.ExecuteScalar();
oleDbConn.Close ();
return price * howMany;
}
catch(Exception e)
{
throw new Exception ("Error calculating cost: " + e.Message );
}
}
[WebMethod]
public Product GetProductInfo(string productName)
{
Product product = new Product ();
try
{
OleDbConnection oleDbConn2 = new OleDbConnection ("Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand ();
oleDbCmd.CommandText = "SELECT * FROM Products WHERE ProductName = '" +
productName + "'";
oleDbCmd.Connection = oleDbConn2;
oleDbConn2.Open ();
OleDbDataReader productData = oleDbCmd.ExecuteReader ();
if (productData.Read ())
{
product.ProductID = productData.GetInt32(0);
product.ProductName = productData.GetString(1);
product.SupplierID = productData.GetInt32(2);
product.CategoryID = productData.GetInt32(3);
product.QuantityPerUnit = productData.GetString(4);
product.UnitPrice = productData.GetDecimal(5);
product.UnitsInStock = productData.GetInt16(6);
product.UnitsOnOrder = productData.GetInt16(7);
product.ReorderLevel = productData.GetInt16(8);
product.Discontinued = productData.GetBoolean(9);
}
else
{
throw new Exception ("Product " + productName + " not found");
}
productData.Close ();
oleDbConn2.Close ();
return product;
}
catch(Exception e)
{
throw new Exception ("Error finding product: " + e.Message );
}
Nov 16 '05 #1
3 1875
Hi,

Compile the application in debug mode as the local user (Local host) and put
a break point to the begining of the web service method... and debug it.

simple as that to get the exact error..

I am sorry if you are not using any standard development kit...

Nirosh.

"silesius" <lo**@this.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi all,
I'm new to asp.net and are just working on a few examples to get some
practice. The following is a simple webservice with two web methods. The
HowMuchWillItCost method works fine the GetProductInfo method returns http
500 internal server error. Maybe someone could tell me what am I doing
wrong?
I suspect it has something to do with connecting to the DB but can't figure out what exactly is causing the error.
TIA
Rich

[WebMethod]
public decimal HowMuchWillItCost(string productName, int howMany)
{
try
{
OleDbConnection oleDbConn = new OleDbConnection ("Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand();
oleDbCmd.CommandText = "SELECT UnitPrice FROM Products WHERE ProductName =
'" + productName + "'";
oleDbCmd.Connection = oleDbConn;
oleDbConn.Open ();
decimal price = (decimal)oleDbCmd.ExecuteScalar();
oleDbConn.Close ();
return price * howMany;
}
catch(Exception e)
{
throw new Exception ("Error calculating cost: " + e.Message );
}
}
[WebMethod]
public Product GetProductInfo(string productName)
{
Product product = new Product ();
try
{
OleDbConnection oleDbConn2 = new OleDbConnection ("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand ();
oleDbCmd.CommandText = "SELECT * FROM Products WHERE ProductName = '" +
productName + "'";
oleDbCmd.Connection = oleDbConn2;
oleDbConn2.Open ();
OleDbDataReader productData = oleDbCmd.ExecuteReader ();
if (productData.Read ())
{
product.ProductID = productData.GetInt32(0);
product.ProductName = productData.GetString(1);
product.SupplierID = productData.GetInt32(2);
product.CategoryID = productData.GetInt32(3);
product.QuantityPerUnit = productData.GetString(4);
product.UnitPrice = productData.GetDecimal(5);
product.UnitsInStock = productData.GetInt16(6);
product.UnitsOnOrder = productData.GetInt16(7);
product.ReorderLevel = productData.GetInt16(8);
product.Discontinued = productData.GetBoolean(9);
}
else
{
throw new Exception ("Product " + productName + " not found");
}
productData.Close ();
oleDbConn2.Close ();
return product;
}
catch(Exception e)
{
throw new Exception ("Error finding product: " + e.Message );
}

Nov 16 '05 #2
This won't help as the poster replaces the real exception with a custom one we need to get rid of that first.

<rest of comments inline>

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eq**************@TK2MSFTNGP10.phx.gbl>

Hi,

Compile the application in debug mode as the local user (Local host) and put
a break point to the begining of the web service method... and debug it.

simple as that to get the exact error..

I am sorry if you are not using any standard development kit...

Nirosh.
[WebMethod]
public Product GetProductInfo(string productName)
{
Product product = new Product ();
try
{
OleDbConnection oleDbConn2 = new OleDbConnection ("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand ();
oleDbCmd.CommandText = "SELECT * FROM Products WHERE ProductName = '" + Select * is a really bad idea as the column order may change in the database
productName + "'";
oleDbCmd.Connection = oleDbConn2;
oleDbConn2.Open ();
OleDbDataReader productData = oleDbCmd.ExecuteReader ();
if (productData.Read ())
{
product.ProductID = productData.GetInt32(0);
product.ProductName = productData.GetString(1);
product.SupplierID = productData.GetInt32(2);
product.CategoryID = productData.GetInt32(3);
product.QuantityPerUnit = productData.GetString(4);
product.UnitPrice = productData.GetDecimal(5);
product.UnitsInStock = productData.GetInt16(6);
product.UnitsOnOrder = productData.GetInt16(7);
product.ReorderLevel = productData.GetInt16(8);
product.Discontinued = productData.GetBoolean(9); Hard coding the ordinals is not a good idea use the GetOrdinal method on the reader to get the odinal for each column. My suspicion is that one of the column types doesn't match the type you are coercing it to.
}
else
{
throw new Exception ("Product " + productName + " not found");
}
productData.Close ();
oleDbConn2.Close ();
return product;
}
catch(Exception e)
{
throw new Exception ("Error finding product: " + e.Message ); This is masking the real error - pass e as the inner exception in the constructor of your new one.
}


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #3
Damn, my attempts to inline comments really aren't working at all - let me try to space out my comments again

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<OH*************@tk2msftngp13.phx.gbl>

This won't help as the poster replaces the real exception with a custom one we need to get rid of that first.

<rest of comments inline>

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eq**************@TK2MSFTNGP10.phx.gbl>

Hi,

Compile the application in debug mode as the local user (Local host) and put
a break point to the begining of the web service method... and debug it.

simple as that to get the exact error..

I am sorry if you are not using any standard development kit...

Nirosh.
[WebMethod]
public Product GetProductInfo(string productName)
{
Product product = new Product ();
try
{
OleDbConnection oleDbConn2 = new OleDbConnection ("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=C:\\Documents and Settings\\Richard\\Desktop\\db2.mdb;Jet
OLEDB:Engine Type=5;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User
ID=Admin;Jet OLEDB:Global Bulk Transactions=1");
OleDbCommand oleDbCmd = new OleDbCommand ();
oleDbCmd.CommandText = "SELECT * FROM Products WHERE ProductName = '" + [Richard Blewett] Select * is a really bad idea as the column order may change in the database [/Richard Blewett] > productName + "'"; oleDbCmd.Connection = oleDbConn2;
oleDbConn2.Open ();
OleDbDataReader productData = oleDbCmd.ExecuteReader ();
if (productData.Read ())
{
product.ProductID = productData.GetInt32(0);
product.ProductName = productData.GetString(1);
product.SupplierID = productData.GetInt32(2);
product.CategoryID = productData.GetInt32(3);
product.QuantityPerUnit = productData.GetString(4);
product.UnitPrice = productData.GetDecimal(5);
product.UnitsInStock = productData.GetInt16(6);
product.UnitsOnOrder = productData.GetInt16(7);
product.ReorderLevel = productData.GetInt16(8);
product.Discontinued = productData.GetBoolean(9); [Richard Blewett] Hard coding the ordinals is not a good idea use the GetOrdinal method on the reader to get the odinal for each column. My suspicion is that one of the column types doesn't match the type you are coercing it to. [/Richard Blewett]
}
else
{
throw new Exception ("Product " + productName + " not found");
}
productData.Close ();
oleDbConn2.Close ();
return product;
}
catch(Exception e)
{
throw new Exception ("Error finding product: " + e.Message ); [Richard Blewett] This is masking the real error - pass e as the inner exception in the constructor of your new one. [/Richard Blewett]
}


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: MA | last post by:
Hi all! I know there is other newsgroups for webservices, but I don´t get any answers on those. I have developed a webservice that writeing and reading files in different folders. Question...
2
by: farseer | last post by:
Hi, I have a few webservice questions i'd like to bounce of you... 1. Can a webservice contain a paramterized contructor ( can't the contructor take parameters )? 2. If two users make an...
4
by: MacLanca | last post by:
Hi, I've done the HelloWorld WebService, installed in a WebServer (INTERNET) When I call it with Windows App it works, if I use a webform it doesn’t (INTERNET) Both of them work in the INTRANET...
8
by: Topper | last post by:
Hello. I have simple web folders structure: -ROOT - BIN WebService.dll WebService.asmx I need to use my WebService.dll not in bin folder - for example, in ROOT. How do i this? How can i do...
1
by: hazz | last post by:
if I think about efficiently sending data back and forth through a webservice for a 'typical' application (in this case smart client using Composite UI application block) what questions do I ask...
1
by: batista | last post by:
Hi, I'm using webservice.htc to call a non-secure(without https) webservice method from a webpage. Now, if the webpage is not under https then everything works fine. But, when enable ssl in...
7
by: Robbert van Geldrop | last post by:
Hello, I have a problem in a C# client that consumes a webservice which is wrapped by WSE 2.0 sp3: The WebService works fine but very rarely my client comes in a state where every call to the...
2
by: Techno_Dex | last post by:
I have a custom object that I have written which is serializable. I have put this object in it's own dll which is referenced by both the WebService and the Application using it. My problem is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.