Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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() 
{
//Create Dataset tables
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;

//DEFINE THE DATABASE DSN NAME & LOGIN INFORMATION
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://MySystem/MyWebService/>
- <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() 
{
//Create Dataset tables
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;

//DEFINE THE DATABASE DSN NAME & LOGIN INFORMATION
dataBase.DSN =" microsoft access database"; 
dataBase.UserName ="admin"; 
dataBase.Password ="password";
bool connected = dataBase.Connect((int)(DatabaseConnectOptionConstants.PromptNoResolve), dataBase.hWndOwner); 
 // comment the connection logic
/* if (!connected) 
{
  DataRow drInspections = dtInspections.NewRow(); 
  drInspections[0] =
  Convert.ToInt16(DatabaseConnectOptionConstants.PromptNoResolve).ToString() + ", " + connected.ToString(); 
  dtInspections.Rows.Add(drInspections);
 return dsInspections; 
}*/
}

try
{
   if (oWkstInfo.Find(dataBase, 0))
     {  
          logic ; 
      }
}


Exception:
<?xml version="1.0" encoding="utf-8" ?> 
- <DataSet xmlns=http://MySystem/MyWebService/>
- <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
Posted
Updated 7-Dec-09 2:35am
v6

System.IndexOutOfRangeException is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array.

The only use of array that I can see here is :
drInspections[0] =
Convert.ToInt16(DatabaseConnectOptionConstants.PromptNoResolve).ToString() + ", " + connected.ToString(); 


So check if drInspections.ItemArray.Length > 0

and then perform this. :cool:
 
Share this answer
 
Hi All,

I included the <systemname>/ASPNET users account and granted read and write permission for the folder containing .mdb file . Now I am able to access the microsoft access database from the web service application.

Thanks & Regards,
Haresh
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900