Rik L

Rik L

  • NA
  • 5
  • 0

Simple webservice, big error : System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

Oct 13 2009 10:51 AM
Hello folks, I'm new here, i've just started learning c# from a book! I've run into a problem though. My current assignment is to create a simple webservice that fetches data from an access db, fills a dataset and the converts it to an array of structs so it can be read by Flash. I've used the exact same code as in the book but when i try to invoke my webservice i get a big error message:

System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.
at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)
at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
at System.Data.OleDb.OleDbConnectionString..ctor(String connectionString, Boolean validate)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)
at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)
at System.Data.OleDb.OleDbConnection.ConnectionString_Set(String value)
at System.Data.OleDb.OleDbConnection.set_ConnectionString(String value)
at Service.GetCustomers() in c:\WINDOWS\VS.NET\ch9\App_Code\Service.cs:line 33

Here is the code in my service.cs file:

using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections;
using System.Data.OleDb;
using System.Data;

[WebService(Namespace = "http://localhost/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]

public class Service : System.Web.Services.WebService{

public Service () {
//Uncomment the following line if using designed components
//InitializeComponent();
}

public struct Customer
{
public string CustomerId;
public string CompanyName;
public string ContactName;
public string ContactTitle;
public string Address;
public string City;
public string Country;
}

[WebMethod]
public Customer[] GetCustomers(){
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"C:\VSNET\ch9\App_Data\Northwind.mdb";

OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Country FROM Customers";

OleDbCommand cmd2 = new OleDbCommand();
cmd2.Connection = conn;
cmd2.CommandText = "SELECT COUNT(CustomerID) FROM Customers";

conn.Open();

int count = (int)cmd2.ExecuteScalar();

OleDbDataReader dr = cmd.ExecuteReader();
Customer[] _customers = new Customer[count];
int ct = 0;
while (dr.Read()){
Customer _cust = new Customer();
_cust.CustomerId = dr.GetString(0);
_cust.CompanyName = dr.GetString(1);
_cust.ContactName = dr.GetString(2);
_cust.ContactTitle = dr.GetString(3);
_cust.Address = dr.GetString(4);
_cust.City = dr.GetString(5);
_cust.Country = dr.GetString(6);
_customers[ct] = _cust;
ct++;
}
dr.Close();
conn.Close();
return _customers;
}
}

I only have a very basic understanding of what the stuff in this script does, so i have no idea what this error means. I kinda need to finish this webservice before i can go on with the following chapters so any help would be appreciated!

Answers (3)