Simple db-problem

L

Lasse Edsvik

Hello

Anyone know why i get:

Exception Details: System.ArgumentException: Format of the initialization
string does not conform to specification starting at index 0.

Line 14: OleDbConnection conn = new OleDbConnection("ConnectionString");


Web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=127.0.0.1,1433;Network
Library=DBMSSOCN;Initial Catalog=northwind;User ID=sa;Password="/>
</appSettings>
<system.web>
</system.web>
</configuration>


code:

using System;

using System.Data;

using System.Data.OleDb;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

OleDbConnection conn = new OleDbConnection("ConnectionString");

OleDbCommand cmd = new OleDbCommand("SalesByCategory",conn);

cmd.CommandType = CommandType.StoredProcedure;

// do stuff

conn.Close();

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}
 
H

Hans Kesting

Lasse said:
Hello

Anyone know why i get:

Exception Details: System.ArgumentException: Format of the
initialization string does not conform to specification starting at
index 0.

Line 14: OleDbConnection conn = new
OleDbConnection("ConnectionString");

You supply the string "ConnectionString" as connection string, and that is
*not* the correct format :)
You want this:
OleDbConnection conn = new OleDbConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);

By the way, you seem to connect to SqlServer. There are specific classes
tuned for SqlServer! (SqlConnection, SqlCommand etc)

Hans Kesting
 
L

Lasse Edsvik

Hans,

Ok, i'll try with sqlclasses, but i still get same error


and when i type ConfigurationSettings i dont get any methods or properties.
whats missing?



Hans Kesting said:
Lasse said:
Hello

Anyone know why i get:

Exception Details: System.ArgumentException: Format of the
initialization string does not conform to specification starting at
index 0.

Line 14: OleDbConnection conn = new
OleDbConnection("ConnectionString");

You supply the string "ConnectionString" as connection string, and that is
*not* the correct format :)
You want this:
OleDbConnection conn = new OleDbConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);

By the way, you seem to connect to SqlServer. There are specific classes
tuned for SqlServer! (SqlConnection, SqlCommand etc)

Hans Kesting

Web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data
Source=127.0.0.1,1433;Network Library=DBMSSOCN;Initial
Catalog=northwind;User ID=sa;Password="/> </appSettings>
<system.web>
</system.web>
</configuration>


code:

using System;

using System.Data;

using System.Data.OleDb;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

private void Page_Load(object sender, System.EventArgs e)

{

OleDbConnection conn = new OleDbConnection("ConnectionString");

OleDbCommand cmd = new OleDbCommand("SalesByCategory",conn);

cmd.CommandType = CommandType.StoredProcedure;

// do stuff

conn.Close();

// Put user code to initialize the page here

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}
 
H

Hans Kesting

Lasse said:
Hans,

Ok, i'll try with sqlclasses, but i still get same error


and when i type ConfigurationSettings i dont get any methods or
properties. whats missing?

add this to the top of the class file:
using System.Configuration;

then it should work

Hans Kesting
Hans Kesting said:
Lasse said:
Hello

Anyone know why i get:

Exception Details: System.ArgumentException: Format of the
initialization string does not conform to specification starting at
index 0.

Line 14: OleDbConnection conn = new
OleDbConnection("ConnectionString");

You supply the string "ConnectionString" as connection string, and
that is *not* the correct format :)
You want this:
OleDbConnection conn = new OleDbConnection(
ConfigurationSettings.AppSettings["ConnectionString"]);

By the way, you seem to connect to SqlServer. There are specific
classes tuned for SqlServer! (SqlConnection, SqlCommand etc)

Hans Kesting
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top