Hi,
We have created a web service using File-> Web site -> ASP.Web service in Visual Studio 2008. We are using an application API which is accessible through Visual Studio, after adding references to DLLs . After defining the Microsoft access database DSN name and login infomation, if I check for the connectivity using a bool type I am getting "False". The code is as follows:
public DataSet dsInspections = null;
public Database dataBase = new Database();
[WebMethod]
public DataSet AccessData()
{
dsInspections = new DataSet();
DataTable dtInspections = new DataTable();
dtInspections.Columns.Add(
"WkstName", typeof(System.String)).AllowDBNull = true;
dtInspections.Columns.Add(
"WkstId", typeof(System.String)).AllowDBNull = true;
dataBase.DSN =" microsoft access database";
dataBase.UserName ="admin";
dataBase.Password ="password";
bool connected = dataBase.Connect((int)(DatabaseConnectOptionConstants.PromptNoResolve), dataBase.hWndOwner);
if (!connected)
{
DataRow drInspections = dtInspections.NewRow();
drInspections[0] =
Convert.ToInt16(DatabaseConnectOptionConstants.PromptNoResolve).ToString() + ", " + connected.ToString();
dtInspections.Rows.Add(drInspections);
return dsInspections;
}
}
Exception:
<?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns=http:
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Table1">
- <xs:complexType>
- <xs:sequence>
<xs:element name="WkstName" type="xs:string" minOccurs="0" />
<xs:element name="WkstId" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <NewDataSet xmlns="">
- <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<WkstName>2, False</WkstName>
</Table1>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
If I do not check for connection of database in the code, using try and catch, I get a "
System.IndexOutORange.Exception
".
public DataSet dsInspections = null;
public Database dataBase = new Database();
[WebMethod]
public DataSet AccessData()
{
dsInspections = new DataSet();
DataTable dtInspections = new DataTable();
dtInspections.Columns.Add(
"WkstName", typeof(System.String)).AllowDBNull = true;
dtInspections.Columns.Add(
"WkstId", typeof(System.String)).AllowDBNull = true;
dataBase.DSN =" microsoft access database";
dataBase.UserName ="admin";
dataBase.Password ="password";
bool connected = dataBase.Connect((int)(DatabaseConnectOptionConstants.PromptNoResolve), dataBase.hWndOwner);
}
try
{
if (oWkstInfo.Find(dataBase, 0))
{
logic ;
}
}
Exception:
<?xml version="1.0" encoding="utf-8" ?>
- <DataSet xmlns=http:
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
- <xs:complexType>
- <xs:choice minOccurs="0" maxOccurs="unbounded">
- <xs:element name="Table1">
- <xs:complexType>
- <xs:sequence>
<xs:element name="WkstName" type="xs:string" minOccurs="0" />
<xs:element name="WkstId" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
- <NewDataSet xmlns="">
- <Table1 diffgr:id="Table11" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<WkstName>System.IndexOutOfRangeException: Subscript out of range at WkstInfClass.Find(Database DB, Int32 Options) at Service.AccessData() in c:\Inetpub\wwwroot\MyWebService\App_Code\Service.cs:line 193</WkstName>
</Table1>
</NewDataSet>
</diffgr:diffgram>
</DataSet>
I felt there is a problem in establishing the connection to the Microsoft Access database from the web service application. So I have configured the IIS 6.0 to ODBC logging according to the link
http://support.microsoft.com/kb/245243. Could you let me know where I am going wrong.
Thanks & Regards,
Haresh