Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I m using C# windows program in Visual Studio 2008 with MS Access at run time I m getting error (Format of the initialization string does not conform to specification starting at index 0.) bellow given the program

public partial class partmaster : Form
   {
       private OdbcConnection con = new OdbcConnection();
       private basecon obj = new basecon(); //basecon is a class file

private void partmaster_Load(object sender, EventArgs e)
       {
           grid();
       }

 private void grid()
       {
           dgvPartMaster.Columns.Clear();
           DataGridViewTextBoxColumn dgvCol = new DataGridViewTextBoxColumn();
           con.ConnectionString = Microsoft.VisualBasic.Strings.Trim(obj.connection().ToString()); // error is showing (Format of the initialization string does not conform to specification starting at index 0.)
           con.Open();
           string qry;
Posted
Updated 25-Jul-11 19:34pm
v2
Comments
Kim Togo 26-Jul-11 1:52am    
What value has obj.connection().ToString() ?
Syed Salman Raza Zaidi 26-Jul-11 1:55am    
Can you share the value of connection string??

1 solution

try changing this line:

private OdbcConnection con = new OdbcConnection();


to this:

private OleDbConnection con = new OleDbConnection();


and you can call your mdb file like this in your app.config:

XML
<connectionStrings>
    <add name="myconn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}App_Data\mydb.mdb" providerName="System.Data.OleDb"/>
  </connectionStrings>


hope it helps :)
 
Share this answer
 
Comments
IndrajitDasgupat 26-Jul-11 2:45am    
public string connection()
{
string p;
p = Application.StartupPath.ToString() + @"\conn.ini";
string str;
FileStream fs;
str = "";
try
{
fs = new FileStream(p, FileMode.Open, FileAccess.Read);// error from here it is going to catch block

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