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
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. check this

check this

Scheduled Pinned Locked Moved .NET (Core and Framework)
sysadmin
14 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.
  • K Offline
    K Offline
    kulandaivel_mca2007
    wrote on last edited by
    #1

    public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...

    A L W 3 Replies Last reply
    0
    • K kulandaivel_mca2007

      public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Please Don't Cross Post X|

      cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net

      1 Reply Last reply
      0
      • K kulandaivel_mca2007

        public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I don't know if you can treat an arbitrary text as a database. A CSV-text, no problems. It kinda depends on the format of your textfile. Can you show us a small excerpt (5 lines), including escape-characters? Anyway, if you want to verify that your connection-string works and can connect to the datastore, invoke the function described below;

        /// Used to determine whether we can connect to a db-instance as provided
        /// By a connectionstring.
        internal bool TryConnectToSqlInstance(string connectionString)
        {
        using (SqlConnection con = new SqlConnection(connectionString))
        try
        {
        con.Open();
        }
        catch (SqlException ex)
        {
        MessageBox.Show(String.Format("{0}\n\nConnection string: '{1}'", Message, connectionString}
        Application.ProductName,
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);
        }
        finally
        {
        while (con.State == ConnectionState.Connecting)
        Application.DoEvents();
        if (con.State == ConnectionState.Open)
        MessageBox.Show("Connection Succeeded!",
        Application.ProductName,
        MessageBoxButtons.OK,
        MessageBoxIcon.Information);
        }
        }

        You might also be interested in this[^] link, where you can find various connectionstrings for almost every database.

        I are troll :)

        1 Reply Last reply
        0
        • K kulandaivel_mca2007

          public string connection = "Provider=SQLOLEDB; Data Source=D:king.txt;Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn"; SqlConnection con1 = new SqlConnection(connection); in my text file king i gave this text "veeserv3" <--(this is my data source name) is it right...

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

          No, you cannot refer to the contents of the text file as the data source. Use config file or read the text from the textfile, for example using File.ReadAllLines[^] amd then place the contents to your connection string. Something like:

          string[] datasource = File.ReadAllLines("D:\\king.txt");
          string connection = "Provider=SQLOLEDB; Data Source="
          + datasource[0]
          + ";Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn";

          The need to optimize rises from a bad design.My articles[^]

          modified on Thursday, January 22, 2009 12:15 PM

          K 1 Reply Last reply
          0
          • W Wendelius

            No, you cannot refer to the contents of the text file as the data source. Use config file or read the text from the textfile, for example using File.ReadAllLines[^] amd then place the contents to your connection string. Something like:

            string[] datasource = File.ReadAllLines("D:\\king.txt");
            string connection = "Provider=SQLOLEDB; Data Source="
            + datasource[0]
            + ";Catalog=STU_ATTENDANCE;User ID=sa;Password=sa; Network Library=dbmssocn";

            The need to optimize rises from a bad design.My articles[^]

            modified on Thursday, January 22, 2009 12:15 PM

            K Offline
            K Offline
            kulandaivel_mca2007
            wrote on last edited by
            #5

            nice gentle man u got my problem... when i include those lines i get this error.... "File does Not exist in the current context"

            W 1 Reply Last reply
            0
            • K kulandaivel_mca2007

              nice gentle man u got my problem... when i include those lines i get this error.... "File does Not exist in the current context"

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

              File class is under System.IO namespace, so you can refer to it like System.IO.File.ReadAllLines(... or add using System.IO directive to your file.

              The need to optimize rises from a bad design.My articles[^]

              K 1 Reply Last reply
              0
              • W Wendelius

                File class is under System.IO namespace, so you can refer to it like System.IO.File.ReadAllLines(... or add using System.IO directive to your file.

                The need to optimize rises from a bad design.My articles[^]

                K Offline
                K Offline
                kulandaivel_mca2007
                wrote on last edited by
                #7

                i got this error Could not find file 'D:\king.txt'. but i have word file in my d:

                W 1 Reply Last reply
                0
                • K kulandaivel_mca2007

                  i got this error Could not find file 'D:\king.txt'. but i have word file in my d:

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

                  As the message says, the file cannot be opened. Re-chek the path and the name and if another application is having that file open, close the other application first.

                  The need to optimize rises from a bad design.My articles[^]

                  K 1 Reply Last reply
                  0
                  • W Wendelius

                    As the message says, the file cannot be opened. Re-chek the path and the name and if another application is having that file open, close the other application first.

                    The need to optimize rises from a bad design.My articles[^]

                    K Offline
                    K Offline
                    kulandaivel_mca2007
                    wrote on last edited by
                    #9

                    the file did not open any where in my project... i gave like this... string[] datasource = File.ReadAllLines("D:\\king.txt"); Could not find file 'D:\king.txt'. if i give like this.... string[] datasource = File.ReadAllLines("D:\king.txt"); Error 1 Unrecognized escape sequence //occurs i gave like this... string[] datasource = File.ReadAllLines("D:king.txt"); Could not find file 'D:\king.txt'.

                    W 1 Reply Last reply
                    0
                    • K kulandaivel_mca2007

                      the file did not open any where in my project... i gave like this... string[] datasource = File.ReadAllLines("D:\\king.txt"); Could not find file 'D:\king.txt'. if i give like this.... string[] datasource = File.ReadAllLines("D:\king.txt"); Error 1 Unrecognized escape sequence //occurs i gave like this... string[] datasource = File.ReadAllLines("D:king.txt"); Could not find file 'D:\king.txt'.

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

                      The problem isn't in your code, but the code cannot open the file from the operating system. Check (for example using windows explorer) that: - the file is on drive D and in the root directory - the file is named king.txt - you have privileges to open the file - the file isn't open in any program, for example in Microsoft Word etc.

                      The need to optimize rises from a bad design.My articles[^]

                      K 1 Reply Last reply
                      0
                      • W Wendelius

                        The problem isn't in your code, but the code cannot open the file from the operating system. Check (for example using windows explorer) that: - the file is on drive D and in the root directory - the file is named king.txt - you have privileges to open the file - the file isn't open in any program, for example in Microsoft Word etc.

                        The need to optimize rises from a bad design.My articles[^]

                        K Offline
                        K Offline
                        kulandaivel_mca2007
                        wrote on last edited by
                        #11

                        file read successfully but.. reading in this manner ::ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0\t\0\0\0ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0

                        W 1 Reply Last reply
                        0
                        • K kulandaivel_mca2007

                          file read successfully but.. reading in this manner ::ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0>\0\0\t\0\0\0ࡱ\0\0\0\0\0\0\0\0\0\0\0\0\0

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

                          Are you sure it's a plain text file and not for example in Word format? Open it using notepad. It should answer that question. File-class reads the text as plain text. If the file contains some other format, File class is unable to "translate" it to text.

                          The need to optimize rises from a bad design.My articles[^]

                          K 1 Reply Last reply
                          0
                          • W Wendelius

                            Are you sure it's a plain text file and not for example in Word format? Open it using notepad. It should answer that question. File-class reads the text as plain text. If the file contains some other format, File class is unable to "translate" it to text.

                            The need to optimize rises from a bad design.My articles[^]

                            K Offline
                            K Offline
                            kulandaivel_mca2007
                            wrote on last edited by
                            #13

                            i typed "veeserv3" in that word doc... it is not empty... "Format of the initialization string does not conform to specification starting at index 0." this error also occured..

                            K 1 Reply Last reply
                            0
                            • K kulandaivel_mca2007

                              i typed "veeserv3" in that word doc... it is not empty... "Format of the initialization string does not conform to specification starting at index 0." this error also occured..

                              K Offline
                              K Offline
                              kulandaivel_mca2007
                              wrote on last edited by
                              #14

                              VERY VERY THANKS GENTLE MAN... I GOT THE RESULT...

                              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