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 for MySQL in C#.Net2.0

Connection String for MySQL in C#.Net2.0

Scheduled Pinned Locked Moved C#
csharpdatabasemysqlsysadmin
15 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.
  • L Lost User

    What is the exception message ?

    V Offline
    V Offline
    Varun Sareen
    wrote on last edited by
    #6

    Connection Terminated unexpectedly. I would like to add here that now I have installed a local MySQL Server and restored one of the table to fetch data form it. But still I am not able to connect to the database locally also from C#.Net2.0 :(. When the code reaches to mySQLCon.open(), then it fires the above exception. Connection String:"Server=localhost; PORT=80; Data Source=ecampust_opensis; User Id=root; Password=;" Thanks

    1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      Show us the code fragment you are using to access the connection string, and the code fragment you use to open the connection to the DB. (Not the whole program, please, just the relevant bits)

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      V Offline
      V Offline
      Varun Sareen
      wrote on last edited by
      #7

      Web.Config: Containing the connection string Fetching the Connection string into a string connStr and opening the connection: connStr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]; mySQLCon = new MySqlConnection(connStr); mySQLCon.Open();

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Show us the code fragment you are using to access the connection string, and the code fragment you use to open the connection to the DB. (Not the whole program, please, just the relevant bits)

        Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

        V Offline
        V Offline
        Varun Sareen
        wrote on last edited by
        #8

        Now the exception is coming as: {MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts ---> System.Net.Sockets.SocketException: The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for

        OriginalGriffO 1 Reply Last reply
        0
        • V Varun Sareen

          Now the exception is coming as: {MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts ---> System.Net.Sockets.SocketException: The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for

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

          Check your database server: Do you have the Named Pipes protocol enabled in the Network setup? (apparently .NET Sockets likes both Named Pipes and TCP/IP) Also check your firewall at the server - it may be rejecting port 80.

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          "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

          V 2 Replies Last reply
          0
          • V Varun Sareen

            Web.Config: Containing the connection string Fetching the Connection string into a string connStr and opening the connection: connStr = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]; mySQLCon = new MySqlConnection(connStr); mySQLCon.Open();

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #10

            My guess is that you have the wrong port number. Port 80 is normally reserved for HTTP traffic (web browsers/servers).

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            V 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Check your database server: Do you have the Named Pipes protocol enabled in the Network setup? (apparently .NET Sockets likes both Named Pipes and TCP/IP) Also check your firewall at the server - it may be rejecting port 80.

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              V Offline
              V Offline
              Varun Sareen
              wrote on last edited by
              #11

              Hey dear Griff, I would like to ask you here that "As MySQL is open source and there are many articles for connecting the .Net application with MySQL db, and no where I have found that someone have specified this Named Pipes protocol thing in order to connect to MySQL dB although I have checked firewall. As our client is the owner of the MySQL Database, I think some dB level permission is to be granted in order to access the dB remotely. What do you say dear Griff on this? Thanks

              1 Reply Last reply
              0
              • D Dave Kreskowiak

                My guess is that you have the wrong port number. Port 80 is normally reserved for HTTP traffic (web browsers/servers).

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                V Offline
                V Offline
                Varun Sareen
                wrote on last edited by
                #12

                Hey Dave, I am checking the connection locally, so i think the port must be 80 (for all local servers).

                D 1 Reply Last reply
                0
                • V Varun Sareen

                  Hey Dave, I am checking the connection locally, so i think the port must be 80 (for all local servers).

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #13

                  The port number has nothing to do with the server being local or not.

                  Varun Sareen wrote:

                  so i think the port must be 80

                  "Thinking" is not allowed in this business. You either know what the port is, or you have to find out.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  V 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    The port number has nothing to do with the server being local or not.

                    Varun Sareen wrote:

                    so i think the port must be 80

                    "Thinking" is not allowed in this business. You either know what the port is, or you have to find out.

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    V Offline
                    V Offline
                    Varun Sareen
                    wrote on last edited by
                    #14

                    Ok Dave, Thanks

                    1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Check your database server: Do you have the Named Pipes protocol enabled in the Network setup? (apparently .NET Sockets likes both Named Pipes and TCP/IP) Also check your firewall at the server - it may be rejecting port 80.

                      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                      V Offline
                      V Offline
                      Varun Sareen
                      wrote on last edited by
                      #15

                      Hey dear Griff, the error is coming as "Connection unexpectedly terminated". I am just going sick over this issue :(. Kindly help someone.

                      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