dcsimg
Results 1 to 9 of 9

Thread: Format of the initialization string does not conform to specification.....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    466

    Format of the initialization string does not conform to specification.....

    Hello

    When I try to register a new user as part of testing in register.apx, I get the following error:

    Format of the initialization string does not conform to specification starting at index 0.
    which is followed by a lengthy Stack Trace. The error is on this line of my code:

    Using connection As New OleDbConnection("connectionString")

    This is the code in question:

    Code:
    Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
            Dim hashedPassword As String = Crypto.HashPassword(password)
    
            Using connection As New OleDbConnection("connectionString")
    
                'Using connection As New OleDbConnection("...CONNECTION STRING HERE ...")
    
                Using cmd As New OleDbCommand("INSERT INTO university (username, strEmail, hashed) VALUES (@username, @strEmail, @hashed)", connection)
                    cmd.Parameters.AddWithValue("@username", username)
                    cmd.Parameters.AddWithValue("@strEmail", email)
                    cmd.Parameters.AddWithValue("@hashed", hashedPassword)
    
                    connection.Open()
                    cmd.ExecuteNonQuery()
                End Using
            End Using
        End Sub
    The database columns look like this (fictitious emails):

    Name:  AccessScreenshot.jpg
Views: 102
Size:  11.5 KB

    In my Web.config, I have:

    Code:
     <connectionStrings>
        <add name="students" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|students.mdb;" providerName="System.Data.OleDb" />
      </connectionStrings>
    I am not sure what the index 0 error is or what I have to do to correct it.

    Thanks.

  2. #2
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,532

    Re: Format of the initialization string does not conform to specification.....

    First thing that stands out to me is you have no Try Catch block so you not capturing the actual error

    put a Try Catch block around the code in your sub CreateAccount and properly handle your errors and then you might get some information as to what your actual error is

    Code:
    Try
    
    'your code here
    
    Catch ex As Exception
    
     Dim error As String = ex.Message
    
    End Try
    then put a break point in and step through until it hits the catch block then hover over the error string so you can see you error message

    Really as this is a web application you should be using logging of some kind for your errorhanlding as i have recently described in this post here
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,266

    Re: Format of the initialization string does not conform to specification.....

    Actually, not having the try catch is a good thing... the problem is as it stated... it can't use the connection string he gave it:
    Using connection As New OleDbConnection("connectionString")

    It's trying to use the literal string "connectionString" ... which is invalid. If you're trying to use the one from your settings file you should be using (I think I have this right) My.ConnectionStrings.sudents ... it might be My.Settins.connectionStrings.students ... but it's in the My namespace somewhere like that ... and don't use quotes around it.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    466

    Re: Format of the initialization string does not conform to specification.....

    I have tried this:

    Code:
    Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
            Dim hashedPassword As String = Crypto.HashPassword(password)
    
            Try
    
                Using connection As New OleDbConnection("connectionString")
    
                    'Using connection As New OleDbConnection("...CONNECTION STRING HERE ...")
    
                    Using cmd As New OleDbCommand("INSERT INTO university (username, strEmail, hashed) VALUES (@username, @strEmail, @hashed)", connection)
                        cmd.Parameters.AddWithValue("@username", username)
                        cmd.Parameters.AddWithValue("@strEmail", email)
                        cmd.Parameters.AddWithValue("@hashed", hashedPassword)
    
                        connection.Open()
                        cmd.ExecuteNonQuery()
                    End Using
                End Using
    
            Catch ex As Exception
    
                Dim error As String = ex.Message
    
            End Try
        End Sub
    VS has underlined 'error'in red in

    Code:
    Dim error As String = ex.Message
    'Keyword is not valid as an identifier' (not sure what that means, sorry).

    Steve

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    466

    Re: Format of the initialization string does not conform to specification.....

    I have tried this:

    Code:
    Private Sub CreateAccount(ByVal username As String, ByVal password As String, ByVal email As String)
            Dim hashedPassword As String = Crypto.HashPassword(password)
    
            Try
    
                Using connection As New OleDbConnection("connectionString")
    
                    'Using connection As New OleDbConnection("...CONNECTION STRING HERE ...")
    
                    Using cmd As New OleDbCommand("INSERT INTO university (username, strEmail, hashed) VALUES (@username, @strEmail, @hashed)", connection)
                        cmd.Parameters.AddWithValue("@username", username)
                        cmd.Parameters.AddWithValue("@strEmail", email)
                        cmd.Parameters.AddWithValue("@hashed", hashedPassword)
    
                        connection.Open()
                        cmd.ExecuteNonQuery()
                    End Using
                End Using
    
            Catch ex As Exception
    
                Dim error As String = ex.Message
    
            End Try
        End Sub
    VS has underlined 'error'in red in

    Code:
    Dim error As String = ex.Message
    'Keyword is not valid as an identifier' (not sure what that means, sorry).

    Steve

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    466

    Re: Format of the initialization string does not conform to specification.....

    I have replaced the line I got the error for, namely

    Code:
    Using connection As New OleDbConnection("connectionString")
    with

    Code:
     Using connection As OleDbConnection = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings("students").ConnectionString)
    and I am now able to insert the new user into the database.

    But I will try to get to grips with the Try and End Try.

    Thanks!

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,266

    Re: Format of the initialization string does not conform to specification.....

    Quote Originally Posted by SteveHi View Post
    VS has underlined 'error'in red in

    Code:
    Dim error As String = ex.Message
    'Keyword is not valid as an identifier' (not sure what that means, sorry).

    Steve
    It means that the word "Error" is a keword in VB and cannot be used as a variable name.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    40,904

    Re: Format of the initialization string does not conform to specification.....

    Quote Originally Posted by SteveHi View Post
    VS has underlined 'error'in red in

    Code:
    Dim error As String = ex.Message
    'Keyword is not valid as an identifier' (not sure what that means, sorry).
    It means: "the name you want to use is not allowed"

    There are various reasons for that (eg: 11x17 is not allowed because the first character is numeric), but in this case it is most likely to be because Error is a reserved word.

    If you use more descriptive names (such as errorMessage) you are much less likely to get this kind of issue.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2014
    Posts
    466

    Re: Format of the initialization string does not conform to specification.....

    Many thanks to you both for explaining that it is a reserved work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width