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. C#
  4. Connection string Error VS to Mysql

Connection string Error VS to Mysql

Scheduled Pinned Locked Moved C#
databasesysadmincsharpmysqlsql-server
15 Posts 3 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.
  • N Offline
    N Offline
    N Mohamed rafi
    wrote on last edited by
    #1

    I want to insert table in db and make connection to mysql to vs. Error for below code is: System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null. using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Drawing; using System.Threading.Tasks; using System.Data.SqlClient; private void button6_Click(object sender, EventArgs e) { string id = textBox6.Text; string name = textBox7.Text; string salary = textBox8.Text; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; string query = "INSERT INTO employee VALUES(@employee_id, @employee_name, @employee_salary)"; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { cmd.Parameters.AddWithValue("@employee_id", id); cmd.Parameters.AddWithValue("@employee_name", name); cmd.Parameters.AddWithValue("@employee_salary", salary); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } Error for below code is: System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)' private void button8_Click(object sender, EventArgs e) { { string connetionString; SqlConnection cnn; connetionString = @"Data Source=LAPTOP-NDOAR92R;Initial Catalog=testDB;User ID=root;Password=mysql"; cnn = new SqlConnection(connetionString); cnn.Open(); MessageBox.Show("Connection Open!"); cnn.Close(); } }

    OriginalGriffO 1 Reply Last reply
    0
    • N N Mohamed rafi

      I want to insert table in db and make connection to mysql to vs. Error for below code is: System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null. using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Configuration; using System.Windows.Forms; using System.Data; using System.Drawing; using System.Threading.Tasks; using System.Data.SqlClient; private void button6_Click(object sender, EventArgs e) { string id = textBox6.Text; string name = textBox7.Text; string salary = textBox8.Text; textBox6.Text = ""; textBox7.Text = ""; textBox8.Text = ""; string query = "INSERT INTO employee VALUES(@employee_id, @employee_name, @employee_salary)"; string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query)) { cmd.Parameters.AddWithValue("@employee_id", id); cmd.Parameters.AddWithValue("@employee_name", name); cmd.Parameters.AddWithValue("@employee_salary", salary); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } Error for below code is: System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)' private void button8_Click(object sender, EventArgs e) { { string connetionString; SqlConnection cnn; connetionString = @"Data Source=LAPTOP-NDOAR92R;Initial Catalog=testDB;User ID=root;Password=mysql"; cnn = new SqlConnection(connetionString); cnn.Open(); MessageBox.Show("Connection Open!"); cnn.Close(); } }

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Read the error message, it is not only explicit, it tells you what to do to fix it:

      A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

      This may help: Simple SQL Connection String Creation[^]

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      N L 2 Replies Last reply
      0
      • OriginalGriffO OriginalGriff

        Read the error message, it is not only explicit, it tells you what to do to fix it:

        A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

        This may help: Simple SQL Connection String Creation[^]

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        N Offline
        N Offline
        N Mohamed rafi
        wrote on last edited by
        #3

        ok sir please tell step procedure i am very new to it. i don't know to correct it please help me

        OriginalGriffO 1 Reply Last reply
        0
        • N N Mohamed rafi

          ok sir please tell step procedure i am very new to it. i don't know to correct it please help me

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4
          1. DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously. 2) How do you expect me to tell you that step by step, given that I can't see your screen, access your HDD, or have a browse around your network? Did you read the link I gave you?

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          N 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff
            1. DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously. 2) How do you expect me to tell you that step by step, given that I can't see your screen, access your HDD, or have a browse around your network? Did you read the link I gave you?

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            N Offline
            N Offline
            N Mohamed rafi
            wrote on last edited by
            #5

            I don't understand that link sir, please send some more article pages

            OriginalGriffO 1 Reply Last reply
            0
            • N N Mohamed rafi

              I don't understand that link sir, please send some more article pages

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              What part did you not understand? Let's take the instructions one by one...

              Quote:

              Create an empty text file somewhere on your hard disk, called "myfile.udl".

              Have you done that?

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              N 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                What part did you not understand? Let's take the instructions one by one...

                Quote:

                Create an empty text file somewhere on your hard disk, called "myfile.udl".

                Have you done that?

                "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                N Offline
                N Offline
                N Mohamed rafi
                wrote on last edited by
                #7

                Created sir this is the location sir D:\Official\ASP.NET\Projects\Basic After that what i have to do sir?

                OriginalGriffO 1 Reply Last reply
                0
                • N N Mohamed rafi

                  Created sir this is the location sir D:\Official\ASP.NET\Projects\Basic After that what i have to do sir?

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  The link gives teh next instruction:

                  Quote:

                  Double click the file, and the "Data Link Properties" dialog will open:

                  Did you do that? Do you get where I am going with this? Or do I need to copy and paste the whole Tip sentence by sentence as a separate reply to check you have done it?

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  N 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    The link gives teh next instruction:

                    Quote:

                    Double click the file, and the "Data Link Properties" dialog will open:

                    Did you do that? Do you get where I am going with this? Or do I need to copy and paste the whole Tip sentence by sentence as a separate reply to check you have done it?

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                    N Offline
                    N Offline
                    N Mohamed rafi
                    wrote on last edited by
                    #9

                    ok sir data link properties opened and i clicked test connection it shows error like Test connection faile because of an error initializing provider invalid authorization specification then what i have to do now sir?

                    OriginalGriffO 1 Reply Last reply
                    0
                    • N N Mohamed rafi

                      ok sir data link properties opened and i clicked test connection it shows error like Test connection faile because of an error initializing provider invalid authorization specification then what i have to do now sir?

                      OriginalGriffO Offline
                      OriginalGriffO Offline
                      OriginalGriff
                      wrote on last edited by
                      #10

                      Did you follow the instructions between "open the file" and "press the button"? It's saying that the information you provided for that server / database is not valid: the login name, or password for example. If you filled in the info from your existing connection string, then that's why that failed as well: you aren't authorised under that login. We can't fix that, short of coming round to your place and typing on your keyboard - which would cost you a considerable amount of money in time, flights, hotels, taxis, expenses ... So it's probably a good idea if you find out what your login info should be from the person who installed the DB!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                      N 1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        Did you follow the instructions between "open the file" and "press the button"? It's saying that the information you provided for that server / database is not valid: the login name, or password for example. If you filled in the info from your existing connection string, then that's why that failed as well: you aren't authorised under that login. We can't fix that, short of coming round to your place and typing on your keyboard - which would cost you a considerable amount of money in time, flights, hotels, taxis, expenses ... So it's probably a good idea if you find out what your login info should be from the person who installed the DB!

                        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                        N Offline
                        N Offline
                        N Mohamed rafi
                        wrote on last edited by
                        #11

                        ok sir i will try with correct username pwd and get back you soon

                        OriginalGriffO 1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          Read the error message, it is not only explicit, it tells you what to do to fix it:

                          A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

                          This may help: Simple SQL Connection String Creation[^]

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

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

                          Brilliant utility, I could really have done with it yesterday.

                          N 1 Reply Last reply
                          0
                          • N N Mohamed rafi

                            ok sir i will try with correct username pwd and get back you soon

                            OriginalGriffO Offline
                            OriginalGriffO Offline
                            OriginalGriff
                            wrote on last edited by
                            #13

                            :thumbsup:

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                            1 Reply Last reply
                            0
                            • L Lost User

                              Brilliant utility, I could really have done with it yesterday.

                              N Offline
                              N Offline
                              N Mohamed rafi
                              wrote on last edited by
                              #14

                              In Datalink properties if i click server name refresh it shows empty only sir. how to bring that there i don't know sir. My userid password is userid is root and pwd is mysql but if i enter that it shows error sir on data link properties.

                              L 1 Reply Last reply
                              0
                              • N N Mohamed rafi

                                In Datalink properties if i click server name refresh it shows empty only sir. how to bring that there i don't know sir. My userid password is userid is root and pwd is mysql but if i enter that it shows error sir on data link properties.

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

                                I am not @OriginalGriff.

                                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