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. Accessing local database created in VS 2005 [modified]

Accessing local database created in VS 2005 [modified]

Scheduled Pinned Locked Moved Database
databasesql-servervisual-studiosysadminsecurity
2 Posts 2 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 Offline
    L Offline
    Libor Tinka
    wrote on last edited by
    #1

    I have installed and configured MS SQL 2005 Express. Both SQL Server and SQL Server Browser login set to "Local System", Shared Memory, Named Pipes and all the stuff set correctly. If I want to connect to database created in the SQL Server Management Studio, everything is OK, no User ID or Password needed, because of the trusted connection. Then I've added a database in my project and set Windows Authentication in the "Modify Connection...". After running the program, I've got exception number 4060: Cannot open database "AddressBook" requested by the login. The login failed. Login failed for user ''. This is the connection string I've used: SqlConnection myConnection = new SqlConnection( "server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "database=AddressBook;"); Connection test in VS is also OK, only accessing the database (.mdf) programatically using SqlConnection goes wrong. Maybe it's something easy to fix, but I tried books, Google and MSDN without any progress, so I feel desperate from this :(

    M 1 Reply Last reply
    0
    • L Libor Tinka

      I have installed and configured MS SQL 2005 Express. Both SQL Server and SQL Server Browser login set to "Local System", Shared Memory, Named Pipes and all the stuff set correctly. If I want to connect to database created in the SQL Server Management Studio, everything is OK, no User ID or Password needed, because of the trusted connection. Then I've added a database in my project and set Windows Authentication in the "Modify Connection...". After running the program, I've got exception number 4060: Cannot open database "AddressBook" requested by the login. The login failed. Login failed for user ''. This is the connection string I've used: SqlConnection myConnection = new SqlConnection( "server=.\\SQLEXPRESS;" + "Trusted_Connection=yes;" + "database=AddressBook;"); Connection test in VS is also OK, only accessing the database (.mdf) programatically using SqlConnection goes wrong. Maybe it's something easy to fix, but I tried books, Google and MSDN without any progress, so I feel desperate from this :(

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      It sounds like you're trying to work with a detached file, one that isn't a permanently configured database. If that's what you're trying to do, you need to specify the filename in the connection string, using the AttachDBFilename keyword. For more information, see the documentation for SqlConnection.ConnectionString.

      Stability. What an interesting concept. -- Chris Maunder

      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