none
This Error Appears: Format of the initialization string does not conform to specification starting at index 0.

    Question

  • I have saved the database connection string to a key named 'ConnectionString' allowing to access it by calling 'configurationSettings.AppSettings("ConnectionString")

    But a red line comes under the configuration in the part of the : 'configurationSettings.AppSettings("ConnectionString")'. When i run it this error appears: Format of the initialization string does not conform to specification starting at index 0.

    and says:

    Line 4:      Public Shared Function GetCategory() As SqlDataReader
    Line 5:          Dim connection As New SqlConnection(connectionString)
    Line 6:          Dim command As New SqlCommand("GetCategory", connection)
    Line 7:          command.CommandType = CommandType.StoredProcedure
    Line 8:          connection.Open()

    What have i done wrong, can anyone please help me...

    Take a look at the code i have done:

    I have put this in my web.config:

    <configuration>

    <appSettings>

    <add key="connectionString" value="Server=PETE\NetSDK;Integrated Security=True;Initial Catalog=JokePoint" />

    </appSettings>

    and I have put this in my .vb file:

    Public Class Catalog

    Public Shared Function GetCategory() As SqlDataReader

    Dim Connection As New SqlConnection(connectionString)

    Dim Command As New SqlCommand("GetCategory", Connection)

    Command.CommandType = CommandType.StoredProcedure

    Connection.Open()

    Return Command.ExecuteReader(CommandBehavior.CloseConnection)

    End Function

    Private Shared ReadOnly Property connectionString() As String

    Get

    Return ConfigurationSettings.AppSettings("connectionString")

    End Get

    End Property

    End Class

    Dim command As New SqlCommand("GetCategory", connection)

     

    Thanks, Peter


    Friday, July 14, 2006 11:03 AM

Answers


  • One other suggestion. To refer to the ConfigurationSettings class you either need the following Imports statement in your module:

    Imports System.Configuration

    or, you need to fully qualify ConfigurationSettings:

    Return System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")

    Does this fix the problem?
         

    Friday, July 14, 2006 11:48 PM

  • Where does categoryID come from? Is that a column in your stored procedure?
    Saturday, July 15, 2006 2:23 AM

All replies


  • It looks like you might be missing some information in your connection string, such as the Database parameter.

    I would take a look at the examples posted at http://www.connectionstrings.com.

    Friday, July 14, 2006 11:47 AM
  • Hi Paul,

    Thank you for your quick reply...

    I do not understand why i should have a database parameter.

    I looked at the examples you said to look at, but do not see anything that particular stands out to say that is the solution.

    Can u see the particular solution from the examples u have asked me to have a look at?

    Please can u have a look at the coding i have done, as i think it is likely i have made sme silly error, like spelling, or missing out a comma, etc. (even though i have carefull checked it against the code from my book hat i have followed. They also do not mention any reasons to put in database parameters in)

    To me, i see as if i am trying to recall the the information by calling 'connectionstring' from my key i mde in my webconfig file (as below).

    I appreciate any more ideas, Paul regarding either your parameters or maybe you spot the problem of my coding.

    What about me putting things in the right places- i put them in a vb file and a web config. - that is correct-right?

    Peter

    Friday, July 14, 2006 12:04 PM

  • It looks like your connection string is a mixture of two different formats. I can't test it at the moment but it seems that if you specify the Server parameter, as in your example, then you need to specify the Database parameter. See if the following works:

    "Server=PETE\NetSDK;Database=JokePoint;Trusted_Connection=True;"

    I can't really verify your Server name parameter so I'm assuming that you're referring to a specific SQL Server instance. This would be applicable to SQL Server 2000.

    Friday, July 14, 2006 12:29 PM
  • SQL Server 2005 connection strings from www.connectionstrings.com

    Standard Security:

    "Data Source=Aron1;Initial Catalog=pubs;User Id=sa;Password=asdasd;"
       - or -
    "Server=Aron1;Database=pubs;User ID=sa;Password=asdasd;Trusted_Connection=False"
       (both connection strings produces the same result)



     

  •  Trusted Connection:
    "Data Source=Aron1;Initial Catalog=pubs;Integrated Security=SSPI;"
       - or -
    "Server=Aron1;Database=pubs;Trusted_Connection=True;"
       (both connection strings produces the same result)
Friday, July 14, 2006 12:31 PM
  •  

    Hi,

    Thank you for your help,

    If i am right, you think it has to do something regarding the database.

    ... but what i am trying to do is rather than establish a connection to the database directly. Instead i have made a 'key, or value' that stores configuration data that applies to the whole application and it would be applied easily via referring to the 'key', therefore i can access this information by calling the key (which i have called 'connectionstring'. I have done this as shown in the coding in a .vb file.

    The error appears in the .vb file when i try to call the 'key', and far as i understand it does not seem to understand the 'configuration'.

    I think it may not think it has been declared!!! How can i double check to see if it has been declared, from the code i have shown in my first post? Would i need to say something like : 'Dim .....'??

    Thanks,

    Peter

     

    Friday, July 14, 2006 10:50 PM
  • Hi,

    Thank you for your help,

    If i am right, you think it has to do something regarding the database.

    ... but what i am trying to do is rather than establish a connection to the database directly. Instead i have made a 'key, or value' that stores configuration data that applies to the whole application and it would be applied easily via referring to the 'key', therefore i can access this information by calling the key (which i have called 'connectionstring'. I have done this as shown in the coding in a .vb file.

    The error appears in the .vb file when i try to call the 'key', and far as i understand it does not seem to understand the 'configuration'.

    I think it may not think it has been declared!!! How can i double check to see if it has been declared, from the code i have shown in my first post? Would i need to say something like : 'Dim .....'??

    Thanks,

    Peter

    Friday, July 14, 2006 10:51 PM

  • Could you indicate on which line of code the error occurs? If it happens on line 6, maybe you should open the connection first before creating the Command object.

    The application configuration setting (web.config) and code to retrieve the connection string looks OK to me.

    Friday, July 14, 2006 11:06 PM
  •  

    I see what your saying... that does make sense to me.

    I think though there must be two problems.... because in v/studio... i get a error under the word 'configuration' in the statment of 'configurationsettings.AppSettings("ConnectionString"). The error says 'configurationSettings is not declared'! But it should because as you can see i have put in my webconfig:(right?):

    <configuration>

    <appSettings>

    <add key="connectionString" value="Server=PETE\NetSDK;Integrated Security=True;Initial Catalog=JokePoint" />

    </appSettings>

    </configuration>

    The reason why i say it may be 2 problems beacuse when i tried to run it (F5) the error that came up was:  

    Format of the initialization string does not conform to specification starting at index 0.

    Line 4:  Public Class Catalog
    Line 5:  Public Shared Function GetCategory() As SqlDataReader
    Line 6:  Dim Connection As New SqlConnection(connectionString)
    Line 7:  Dim Command As New SqlCommand("GetCategory", Connection)
    Line 8:  Command.CommandType = CommandType.StoredProcedure
    But there was no error in Visual Studio in the web.config for this error, soi do not 
    know why it appears when i run it.
    I know this is confussing (is to me too) but i was appreciate if you can help me
    to work out why would it not be able to see if the 'ConfigurationSetting' is not declared??
    Peter

    Friday, July 14, 2006 11:22 PM

  • Can you post the complete contents of your web.config file? There could be a small error somewhere else in the file. These syntax errors can be difficult to track down sometimes.
    Friday, July 14, 2006 11:38 PM
  •  

    Yes, sure.

    I will send my web.config and also send you my .vb file (which says it has the configurationsetting not declared):

    The code for the web.config ::

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

    <appSettings>

    <add key="connectionString" value="Server=PETE\NetSDK;Integrated Security=True;Initial Catalog=JokePoint" />

    </appSettings>

    <system.web>

    <!-- DYNAMIC DEBUG COMPILATION

    Set compilation debug="true" to insert debugging symbols (.pdb information)

    into the compiled page. Because this creates a larger file that executes

    more slowly, you should set this value to true only when debugging and to

    false at all other times. For more information, refer to the documentation about

    debugging ASP.NET files.

    -->

    <compilation defaultLanguage="vb" debug="true" />

    <!-- CUSTOM ERROR MESSAGES

    Set customErrors mode="On" or "RemoteOnly" to enable custom error messages, "Off" to disable.

    Add <error> tags for each of the errors you want to handle.

    "On" Always display custom (friendly) messages.

    "Off" Always display detailed ASP.NET error information.

    "RemoteOnly" Display custom (friendly) messages only to users not running

    on the local Web server. This setting is recommended for security purposes, so

    that you do not display application detail information to remote clients.

    -->

    <customErrors mode="RemoteOnly" />

    <!-- AUTHENTICATION

    This section sets the authentication policies of the application. Possible modes are "Windows",

    "Forms", "Passport" and "None"

    "None" No authentication is performed.

    "Windows" IIS performs authentication (Basic, Digest, or Integrated Windows) according to

    its settings for the application. Anonymous access must be disabled in IIS.

    "Forms" You provide a custom form (Web page) for users to enter their credentials, and then

    you authenticate them in your application. A user credential token is stored in a cookie.

    "Passport" Authentication is performed via a centralized authentication service provided

    by Microsoft that offers a single logon and core profile services for member sites.

    -->

    <authentication mode="Windows" />

     

    <!-- AUTHORIZATION

    This section sets the authorization policies of the application. You can allow or deny access

    to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous

    (unauthenticated) users.

    -->

    <authorization>

    <allow users="*" /> <!-- Allow all users -->

    <!-- <allow users="[comma separated list of users]"

    roles="[comma separated list of roles]"/>

    <deny users="[comma separated list of users]"

    roles="[comma separated list of roles]"/>

    -->

    </authorization>

    <!-- APPLICATION-LEVEL TRACE LOGGING

    Application-level tracing enables trace log output for every page within an application.

    Set trace enabled="true" to enable application trace logging. If pageOutput="true", the

    trace information will be displayed at the bottom of each page. Otherwise, you can view the

    application trace log by browsing the "trace.axd" page from your web application

    root.

    -->

    <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />

     

    <!-- SESSION STATE SETTINGS

    By default ASP.NET uses cookies to identify which requests belong to a particular session.

    If cookies are not available, a session can be tracked by adding a session identifier to the URL.

    To disable cookies, set sessionState cookieless="true".

    -->

    <sessionState

    mode="InProc"

    stateConnectionString="tcpip=127.0.0.1:42424"

    sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"

    cookieless="false"

    timeout="20"

    />

    <!-- GLOBALIZATION

    This section sets the globalization settings of the application.

    -->

    <globalization requestEncoding="utf-8" responseEncoding="utf-8" />

    </system.web>

    </configuration>

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    AND THE .VB FILE CODE : :

    Imports System.Data.SqlClient

    Public Class Catalog

    Public Shared Function GetCategory() As SqlDataReader

    Dim Connection As New SqlConnection(connectionString)

    Dim Command As New SqlCommand("GetCategory", Connection)

    Command.CommandType = CommandType.StoredProcedure

    Connection.Open()

    Return Command.ExecuteReader(CommandBehavior.CloseConnection)

    End Function

    Private Shared ReadOnly Property connectionString() As String

    Get

    Return ConfigurationSettings.AppSettings("connectionString")

    End Get

    End Property

    End Class

     

    Friday, July 14, 2006 11:44 PM

  • One other suggestion. To refer to the ConfigurationSettings class you either need the following Imports statement in your module:

    Imports System.Configuration

    or, you need to fully qualify ConfigurationSettings:

    Return System.Configuration.ConfigurationSettings.AppSettings("ConnectionString")

    Does this fix the problem?
         

    Friday, July 14, 2006 11:48 PM
  •  

    Yes, it has... fantastic.... i put the imports system.configuration .... so i will try to run it now...

    .... it came up with a new message:

    Server Error in '/JokePoint' Application.

    DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name categoryID.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a property with the name categoryID.

    Source Error:

    Line 15: 	<ItemTemplate>
    Line 16: 		&nbsp;&raquo;
    Line 17: 		<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl='<%# "../default.aspx?CategoryID=" &amp; DataBinder.Eval(Container.DataItem, "categoryID") &amp; "&amp;CategoryIndex=" &amp; Container.ItemIndex  %>' Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' CssClass="CategoryUnselected">
    Line 18: 		</asp:HyperLink>
    Line 19: 	</ItemTemplate>


    Source File: C:\MyCommerceSite\JokePoint\UserControls\CategoryList.ascx    Line: 17

     

     

    Friday, July 14, 2006 11:54 PM

  • Where does categoryID come from? Is that a column in your stored procedure?
    Saturday, July 15, 2006 2:23 AM
  •  

    Yeah thats right paul...

    the line that it give the problem is:

    <asp:HyperLink id="HyperLink1" runat="server" NavigateUrl='<%# "../default.aspx?CategoryID=" &amp;DataBinder.Eval(Container.DataItem, "CategoryID") &amp; "&amp;CategoryIndex=" &amp; Container.ItemIndex %>'Text=<%#DataBinder.Eval (Container.DataItem, "Name") %>' CssClass="CategoryUnselected">

    But i am not sure what is wrong with the code.

    The stored procedure works when i tested it.

    I have another line of code identical but at the end it is CssClass="CategorySelected" when the item is selected... that one seems okay. If that one is okay, it should be able to connect to the server okay- right?

    Any ideas what the problem maybe...

    Peter

     

    Saturday, July 15, 2006 9:47 AM
  •  

    Paul, this is my stored procedure:

    ALTER PROCEDURE GetCategory AS

    SELECT [Category ID], Name

    FROM Category

    RETURN

    Is that correct... cause the Category ID is two separate words i put it in the brackets.

    when i run it (test it) it works!

    this is the code-behind the file i posted last (if this helps):

     

    Public Class CategoryList

    Inherits System.Web.UI.UserControl

    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Protected WithEvents list As System.Web.UI.WebControls.DataList

    'NOTE: The following placeholder declaration is required by the Web Form Designer.

    'Do not delete or move it.

    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

    'CODEGEN: This method call is required by the Web Form Designer

    'Do not modify it using the code editor.

    InitializeComponent()

    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'Put user code to initialize the page here

    'The departmentIndex parameter is added to the query string when

    'a department link is clicked. You need this because when the

    'page is reloaded, the DataList forgets which link was clicked.

    Dim listIndex As String = Request.QueryString("CategoryIndex")

    'If listIndex has a value, this tells you that the vistor

    'has clicked a category, and you inform the DataList about that

    '(so it can apply correct template for the selected item)

    If Not listIndex Is Nothing Then

    list.SelectedIndex = CInt(listIndex)

    End If

    'GetCategory returns a SqlDataReader object that has

    'two fields: CategoryID and Name. These fields are read in

    'the SelectedItemTemplate and ItemTemplate of the DataList

    list.DataSource = Catalog.GetCategory()

    'Needed to bind the child controls (the Hyperlink controls)

    'to the data source

    list.DataBind()

    End Sub

    End Class

     

    Saturday, July 15, 2006 10:04 AM
  •  

    Hi Paul,

    You were right about the stored procedure... because when i took out the brackets it would not run, because when i made the coloumn for it i left a space between category and id and in the line of the error - i had put category and id as one word -categoryid. Hence it did read the stored procedure cause of the difference.

    So i put a space in between the category and id in the line of the error and now it works.

    Fantastic. Thank you so much for your help Paul.

    ___________________

    Peter

    Saturday, July 15, 2006 10:23 AM
  •  

    Another thing that will cause this error is if you have your sqldatasource SelectCommandType=StoredProcedure when you are using text for your sql query.

     

     

    <ItemTemplate>

    <asp:LinkButton ID="LinkButton1" runat="server" Text='<% Bind("Name") %>'></asp:LinkButton>

    <br />

    </ItemTemplate>

    </asp:DataList>

    <asp:SqlDataSource ID="SqlDataSourceTables" runat="server" ConnectionString='<% ConnectionStringsBig Smileevx66ConnectionString %>' CancelSelectOnNullParameter="true" SelectCommandType="storedProcedure" SelectCommand="SELECT table_name AS Name FROM INFORMATION_SCHEMA.Tables WHERE TABLE_TYPE = 'BASE TABLE'" ></asp:SqlDataSource>

    Tuesday, October 02, 2007 5:16 AM
  • In Some cases while displaying a large number it will be nice if we can format the number to a more readable format
    Like : Reputation Point : 537456
    Can be more readable if we can write it as Reputation Point : 537,456
    ASP.NET provide features like String.Format(format,arg0) to format arguments into different forms.
    For above solution you can implement

    Response.Write(String.Format("{0:#,###}", 123456789));
    Which will print 123,456,789

    {0:#,###} → Known as the format string where “{ ,}”are compulsory to mentation.
    The first part before ':' represent the argument number & it will be an integer.
    The second part after ':' represent the format that you want your argument to be converted.

    Cheers, Eliza
    Thursday, April 29, 2010 9:24 AM
  • I actually got this error when I tried to statically access my database, but once I set the connection string dynamically the error went away w/ no change to the connection string in the web.config.
    Thursday, May 27, 2010 5:41 PM
  • I happened to experience a similar error:

     

    "Format of the initialization string does not conform to specification starting at index 47."

     

    I was using c# in Visual Studio Express 2008 and it was due to my connection string being incorrectly set, in fact I think originally when I got this error I had set one escape carachter too many....

    Monday, June 06, 2011 3:56 PM
  • You also get this error if you omit the @ on the connection string...

    That gives you this error:

    connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\example.mdb";

    That does not:

    connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\example.mdb";

    • Proposed as answer by msr681 Wednesday, August 17, 2011 5:12 AM
    Monday, June 20, 2011 10:38 AM