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
}
}Lasse Edsvik wrote:
> 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
> }
> }
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" <news.2.hansdk@.spamgourmet.com> wrote in message
news:uXjIzVWoEHA.3556@.TK2MSFTNGP10.phx.gbl...
> Lasse Edsvik wrote:
> > 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
> > }
> > }
Lasse Edsvik wrote:
> 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" <news.2.hansdk@.spamgourmet.com> wrote in message
> news:uXjIzVWoEHA.3556@.TK2MSFTNGP10.phx.gbl...
>> Lasse Edsvik wrote:
>>> 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
>
Hans Kesting wrote:
> Lasse Edsvik wrote:
>> 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
Just an additional note: when you use the sql-specific classes, you need
to change the connection string! Look up the SqlConnection.ConnectionString
property in MSDN: (watch out for wrap)
http://msdn.microsoft.com/library/d...stringtopic.asp
Hans Kesting
0 comments:
Post a Comment