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. Database & SysAdmin
  3. Database
  4. Opening A Database Connection [SOLVED]

Opening A Database Connection [SOLVED]

Scheduled Pinned Locked Moved Database
databasesysadminhelpcsharpsql-server
11 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.
  • realJSOPR realJSOP

    I've written a program using C# that is supposed to access a database. When I try to actually open the connection, I get this exception: 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) The database access code is contained in a separate assembly. This same assembly is used in another program (written in VB if that matters) that connects to the same database without any problems at all (on the same machine, with the same user logged in, and using the same connection string). Why am I getting this exception in one program and not in another? EDIT =================== Here are the constructors for both apps: VB: Dim myClass as new MyClass("abc", "def\geh") C# MyClass myClass = new MyClass("abc", "def\geh"); The problem is that VB automatically escapes the backlslash, but c# requires @"def\geh"... Stupid programmer tricks...

    .45 ACP - because shooting twice is just silly
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

    modified on Tuesday, January 19, 2010 2:32 PM

    L Offline
    L Offline
    loyal ginger
    wrote on last edited by
    #2

    Maybe some strings not escaped correctly?

    realJSOPR 1 Reply Last reply
    0
    • L loyal ginger

      Maybe some strings not escaped correctly?

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #3

      The connection string is identical (it's created in the common assembly, and that was the very first thing I checked). EDIT =========== Why was this 1-voted?

      modified on Wednesday, January 20, 2010 5:50 AM

      L 1 Reply Last reply
      0
      • realJSOPR realJSOP

        The connection string is identical (it's created in the common assembly, and that was the very first thing I checked). EDIT =========== Why was this 1-voted?

        modified on Wednesday, January 20, 2010 5:50 AM

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

        A shot in the dark; perhaps a firewall that's blocking one application, and not the other?

        I are Troll :suss:

        realJSOPR 1 Reply Last reply
        0
        • L Lost User

          A shot in the dark; perhaps a firewall that's blocking one application, and not the other?

          I are Troll :suss:

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #5

          I wrote both apps from scratch (neither existed before I got here), and as far as I know, there are no application-specific blocks on our internal firewall.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            I've written a program using C# that is supposed to access a database. When I try to actually open the connection, I get this exception: 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) The database access code is contained in a separate assembly. This same assembly is used in another program (written in VB if that matters) that connects to the same database without any problems at all (on the same machine, with the same user logged in, and using the same connection string). Why am I getting this exception in one program and not in another? EDIT =================== Here are the constructors for both apps: VB: Dim myClass as new MyClass("abc", "def\geh") C# MyClass myClass = new MyClass("abc", "def\geh"); The problem is that VB automatically escapes the backlslash, but c# requires @"def\geh"... Stupid programmer tricks...

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            modified on Tuesday, January 19, 2010 2:32 PM

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #6

            app.config? app manifest? elevation code missing/wrong? :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
            [The QA section does it automatically now, I hope we soon get it on regular forums as well]


            realJSOPR 3 Replies Last reply
            0
            • L Luc Pattyn

              app.config? app manifest? elevation code missing/wrong? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
              [The QA section does it automatically now, I hope we soon get it on regular forums as well]


              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #7

              There is no app.config. There is no manifest (unless vb creates on automagically). There is no elevation code. Authorization is via Windows login

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              1 Reply Last reply
              0
              • L Luc Pattyn

                app.config? app manifest? elevation code missing/wrong? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #8

                Out of curiosity, I created a manifest file, but the vb's version uses the defaults that the C# one does, so I don't think that's the issue.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                1 Reply Last reply
                0
                • realJSOPR realJSOP

                  I've written a program using C# that is supposed to access a database. When I try to actually open the connection, I get this exception: 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) The database access code is contained in a separate assembly. This same assembly is used in another program (written in VB if that matters) that connects to the same database without any problems at all (on the same machine, with the same user logged in, and using the same connection string). Why am I getting this exception in one program and not in another? EDIT =================== Here are the constructors for both apps: VB: Dim myClass as new MyClass("abc", "def\geh") C# MyClass myClass = new MyClass("abc", "def\geh"); The problem is that VB automatically escapes the backlslash, but c# requires @"def\geh"... Stupid programmer tricks...

                  .45 ACP - because shooting twice is just silly
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                  modified on Tuesday, January 19, 2010 2:32 PM

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

                  The only possibility is a bad connection string.

                  realJSOPR 1 Reply Last reply
                  0
                  • L Lost User

                    The only possibility is a bad connection string.

                    realJSOPR Offline
                    realJSOPR Offline
                    realJSOP
                    wrote on last edited by
                    #10

                    That's what I thought but the connection string for both apps is the same. Solved it (see original post for solution)

                    .45 ACP - because shooting twice is just silly
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                    modified on Tuesday, January 19, 2010 2:36 PM

                    1 Reply Last reply
                    0
                    • L Luc Pattyn

                      app.config? app manifest? elevation code missing/wrong? :)

                      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                      I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
                      [The QA section does it automatically now, I hope we soon get it on regular forums as well]


                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #11

                      Solved it (see original post for solution)

                      .45 ACP - because shooting twice is just silly
                      -----
                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                      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