Internal Server Error

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

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top