webservice questions

S

silesius

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 );
}
 
C

Champika Nirosh

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 said:
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 );
}
 
R

Richard Blewett [DevelopMentor]

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/<[email protected]>

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]
 
R

Richard Blewett [DevelopMentor]

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/<[email protected]>

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/<[email protected]>

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top