Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Format of the initialization string does not conform to specification starting at index 0.????

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

Scheduled Pinned Locked Moved C#
databasehelpsql-serversysadminsecurity
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Twyce
    wrote on last edited by
    #1

    I'm trying to export data from my Sql server database to an excel spreadsheet using bulkCopy.The problem is that whenever i run my application throws "Format of the initialization string does not conform to specification starting at index 0" error.Whatam i doing wrong? Here is my code public class CopyData { string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;"; string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'"; public CopyData(string sourceConnectionString, string destinationConnectionString) { _sourceConnectionString = sourceConnectionString; _destinationConnectionString = destinationConnectionString; } public void CopyTable(string StudentModule) { using (SqlConnection source = new SqlConnection(_sourceConnectionString)) { string sql = string.Format("SELECT * FROM [{0}]", StudentModule); SqlCommand command = new SqlCommand(sql, source); source.Open(); SqlDataReader dr = command.ExecuteReader(); //IDataReader dr = command.ExecuteReader(); using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString)) { copy.DestinationTableName = StudentModule; copy.WriteToServer(dr); } } } } i call this class under button export

    L W P 3 Replies Last reply
    0
    • T Twyce

      I'm trying to export data from my Sql server database to an excel spreadsheet using bulkCopy.The problem is that whenever i run my application throws "Format of the initialization string does not conform to specification starting at index 0" error.Whatam i doing wrong? Here is my code public class CopyData { string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;"; string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'"; public CopyData(string sourceConnectionString, string destinationConnectionString) { _sourceConnectionString = sourceConnectionString; _destinationConnectionString = destinationConnectionString; } public void CopyTable(string StudentModule) { using (SqlConnection source = new SqlConnection(_sourceConnectionString)) { string sql = string.Format("SELECT * FROM [{0}]", StudentModule); SqlCommand command = new SqlCommand(sql, source); source.Open(); SqlDataReader dr = command.ExecuteReader(); //IDataReader dr = command.ExecuteReader(); using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString)) { copy.DestinationTableName = StudentModule; copy.WriteToServer(dr); } } } } i call this class under button export

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      That could only happen with the string.Format, but I cannot see anything wrong with it.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      1 Reply Last reply
      0
      • T Twyce

        I'm trying to export data from my Sql server database to an excel spreadsheet using bulkCopy.The problem is that whenever i run my application throws "Format of the initialization string does not conform to specification starting at index 0" error.Whatam i doing wrong? Here is my code public class CopyData { string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;"; string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'"; public CopyData(string sourceConnectionString, string destinationConnectionString) { _sourceConnectionString = sourceConnectionString; _destinationConnectionString = destinationConnectionString; } public void CopyTable(string StudentModule) { using (SqlConnection source = new SqlConnection(_sourceConnectionString)) { string sql = string.Format("SELECT * FROM [{0}]", StudentModule); SqlCommand command = new SqlCommand(sql, source); source.Open(); SqlDataReader dr = command.ExecuteReader(); //IDataReader dr = command.ExecuteReader(); using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString)) { copy.DestinationTableName = StudentModule; copy.WriteToServer(dr); } } } } i call this class under button export

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #3

        Never mind the first post from me. Misread the line. Could it be this one:

        Twyce wrote:

        string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";

        Since you have @ before the string, you don't need to escape backslash (even though it's on a separate string). Using debugger:

        @"part1" + "\\part2" + "\\part3"

        gives

        "part1\\part2\\part3"

        T 2 Replies Last reply
        0
        • W Wendelius

          Never mind the first post from me. Misread the line. Could it be this one:

          Twyce wrote:

          string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";

          Since you have @ before the string, you don't need to escape backslash (even though it's on a separate string). Using debugger:

          @"part1" + "\\part2" + "\\part3"

          gives

          "part1\\part2\\part3"

          T Offline
          T Offline
          Twyce
          wrote on last edited by
          #4

          thanx for ur reply but i get the error when it gets to this line using (SqlConnection source = new SqlConnection(_sourceConnectionString))

          1 Reply Last reply
          0
          • W Wendelius

            Never mind the first post from me. Misread the line. Could it be this one:

            Twyce wrote:

            string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";

            Since you have @ before the string, you don't need to escape backslash (even though it's on a separate string). Using debugger:

            @"part1" + "\\part2" + "\\part3"

            gives

            "part1\\part2\\part3"

            T Offline
            T Offline
            Twyce
            wrote on last edited by
            #5

            i think the problem is with my source connectionString

            1 Reply Last reply
            0
            • T Twyce

              I'm trying to export data from my Sql server database to an excel spreadsheet using bulkCopy.The problem is that whenever i run my application throws "Format of the initialization string does not conform to specification starting at index 0" error.Whatam i doing wrong? Here is my code public class CopyData { string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;"; string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'"; public CopyData(string sourceConnectionString, string destinationConnectionString) { _sourceConnectionString = sourceConnectionString; _destinationConnectionString = destinationConnectionString; } public void CopyTable(string StudentModule) { using (SqlConnection source = new SqlConnection(_sourceConnectionString)) { string sql = string.Format("SELECT * FROM [{0}]", StudentModule); SqlCommand command = new SqlCommand(sql, source); source.Open(); SqlDataReader dr = command.ExecuteReader(); //IDataReader dr = command.ExecuteReader(); using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString)) { copy.DestinationTableName = StudentModule; copy.WriteToServer(dr); } } } } i call this class under button export

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              The problem would appear to be at the line

              string sql = string.Format("SELECT * FROM [{0}]", StudentModule);

              Step over this line in the debugger and see what StudentModule contains.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              T 1 Reply Last reply
              0
              • P Pete OHanlon

                The problem would appear to be at the line

                string sql = string.Format("SELECT * FROM [{0}]", StudentModule);

                Step over this line in the debugger and see what StudentModule contains.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                T Offline
                T Offline
                Twyce
                wrote on last edited by
                #7

                thanx for ur reply.Thing is it throwsan error when the debugger gets to this line using (SqlConnection source = new SqlConnection(_sourceConnectionString))

                P 1 Reply Last reply
                0
                • T Twyce

                  thanx for ur reply.Thing is it throwsan error when the debugger gets to this line using (SqlConnection source = new SqlConnection(_sourceConnectionString))

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #8

                  When you step over this line, what's in _sourceConnectionString? I ask this because you've initialised it to a value, and then you change it in the constructor.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  T 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    When you step over this line, what's in _sourceConnectionString? I ask this because you've initialised it to a value, and then you change it in the constructor.

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    T Offline
                    T Offline
                    Twyce
                    wrote on last edited by
                    #9

                    What do you mean when you say I change it in the constructor? The debugger does not even allo me to step over the line,it just keeps throwing the error

                    P 1 Reply Last reply
                    0
                    • T Twyce

                      What do you mean when you say I change it in the constructor? The debugger does not even allo me to step over the line,it just keeps throwing the error

                      P Offline
                      P Offline
                      Pete OHanlon
                      wrote on last edited by
                      #10

                      The following is your code:

                      public class CopyData
                      {
                      string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;";
                      string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";

                      public CopyData(string sourceConnectionString, string destinationConnectionString)
                      {
                      _sourceConnectionString = sourceConnectionString;
                      _destinationConnectionString = destinationConnectionString;
                      }

                      public void CopyTable(string StudentModule)
                      {
                      using (SqlConnection source = new SqlConnection(_sourceConnectionString))
                      {
                      string sql = string.Format("SELECT * FROM [{0}]", StudentModule);

                      SqlCommand command = new SqlCommand(sql, source);

                      source.Open();
                      SqlDataReader dr = command.ExecuteReader();
                      //IDataReader dr = command.ExecuteReader();

                      using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString))
                      {
                      copy.DestinationTableName = StudentModule;
                      copy.WriteToServer(dr);
                      }
                      }
                      }
                      }

                      I've highlighted the line that changes the value. The code that creates this class is presumably doing something along the lines of CopyData c = new CopyData("connectionString", "destConnectionString");. Step into the CopyTable method and see what the value of _sourceConnectionString is before you execute the line

                      using (SqlConnection source = new SqlConnection(_sourceConnectionString))

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      T 1 Reply Last reply
                      0
                      • P Pete OHanlon

                        The following is your code:

                        public class CopyData
                        {
                        string _sourceConnectionString = "Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;";
                        string _destinationConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "E:\\+PSATECHZ EYES ONLY+\\PSAtechZTimetableSystem\\Students.xls" + "; Extended Properties='Excel 12.0; IMEX=1; HDR=YES'";

                        public CopyData(string sourceConnectionString, string destinationConnectionString)
                        {
                        _sourceConnectionString = sourceConnectionString;
                        _destinationConnectionString = destinationConnectionString;
                        }

                        public void CopyTable(string StudentModule)
                        {
                        using (SqlConnection source = new SqlConnection(_sourceConnectionString))
                        {
                        string sql = string.Format("SELECT * FROM [{0}]", StudentModule);

                        SqlCommand command = new SqlCommand(sql, source);

                        source.Open();
                        SqlDataReader dr = command.ExecuteReader();
                        //IDataReader dr = command.ExecuteReader();

                        using (SqlBulkCopy copy = new SqlBulkCopy(_destinationConnectionString))
                        {
                        copy.DestinationTableName = StudentModule;
                        copy.WriteToServer(dr);
                        }
                        }
                        }
                        }

                        I've highlighted the line that changes the value. The code that creates this class is presumably doing something along the lines of CopyData c = new CopyData("connectionString", "destConnectionString");. Step into the CopyTable method and see what the value of _sourceConnectionString is before you execute the line

                        using (SqlConnection source = new SqlConnection(_sourceConnectionString))

                        Deja View - the feeling that you've seen this post before.

                        My blog | My articles

                        T Offline
                        T Offline
                        Twyce
                        wrote on last edited by
                        #11

                        it is not giving me a particular value just _sourceConnection.sourceConnection

                        W 1 Reply Last reply
                        0
                        • T Twyce

                          it is not giving me a particular value just _sourceConnection.sourceConnection

                          W Offline
                          W Offline
                          Wendelius
                          wrote on last edited by
                          #12

                          I think you're missing Pete's point. In the constructor you modify the value of the predefined _sourceConnectionString. Try adding the following message box:

                          ...
                          public void CopyTable(string StudentModule){
                          System.Windows.Forms.MessageBox.Show("Going to connect to: " + _sourceConnectionString);
                          using (SqlConnection source = new SqlConnection(_sourceConnectionString))
                          {
                          ...

                          What is shown as the connection string that is used for connection? Is it what you would want ("Data Source= sict-sql;Initial Catalog=PSAtechZ;Integrated Security=True;") or something else.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups