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. Database & SysAdmin
  3. Database
  4. SQL connection in Visual studio 2012

SQL connection in Visual studio 2012

Scheduled Pinned Locked Moved Database
databasehelpcsharpc++sql-server
5 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.
  • M Offline
    M Offline
    Member 10174363
    wrote on last edited by
    #1

    I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();

    L Richard DeemingR B 3 Replies Last reply
    0
    • M Member 10174363

      I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();

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

      Try removing the integrated security part of the connection-string. What does the P in ISP stand for?

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      M 1 Reply Last reply
      0
      • M Member 10174363

        I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();

        Richard DeemingR Online
        Richard DeemingR Online
        Richard Deeming
        wrote on last edited by
        #3

        If you want to attach a specific database file with the "user instance" feature, you need to change your connection string: http://www.connectionstrings.com/sqlconnection/using-an-user-instance-on-a-local-sql-server-express-instance/[^] Otherwise, you need to attach the database file to the server before you can connect to it. You then specify the name of the database, not the path to the database file, in the connection string.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        • L Lost User

          Try removing the integrated security part of the connection-string. What does the P in ISP stand for?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          M Offline
          M Offline
          Member 10174363
          wrote on last edited by
          #4

          I tried to remove the integrated securit from connection string but i got the same error. ISP is just a self-definend variabile used ro build the connection string. Thanks again eddy

          1 Reply Last reply
          0
          • M Member 10174363

            I'm trying to connect to northwnd database by using Visual studio 2021 and c++. I have installed "Microsoft SQL Server 2012 - 11.0.2100.60 (X64)" I get the error: 'System.Data.SqlClient.SqlException' in System.Data.dll Cannot open database "E:\C++\Projects\DB\Debug\NORTHWIND" requested by the login. The login failed." with the following code. Can anybody help me?? String ^sqlServerInstance = ".\\SQLEXPRESS"; String ^dbase = "E:\\C++\\Projects\\DB\\Debug\\NORTHWIND"; String ^UID = "myUID"; String ^PWD = "myPWD"; String ^ISP = "true"; String ^myConnectString = "Database=" + dbase + ";Server=" + sqlServerInstance + ";Integrated Security=" + ISP + ";"; SqlConnection ^myConnection = gcnew SqlConnection(myConnectString); myConnection->Open();

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            There are some issues with your connection string. "Database" is the *name* of the database in SQL Server (as you can see it e.g. in SQL Server Management Studio), not the path to the database file. "Integrated Security=true" means that you login with your Windows Credentials. That means, your Windows user must have access rights to the databse. If you want to use a specific (database defined) user, do not use Integrated Security, but set username and password instead. For more information, look at http://www.connectionstrings.com/sql-server/[^].

            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