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. Problem connecting to sql with C# and ASP.NET

Problem connecting to sql with C# and ASP.NET

Scheduled Pinned Locked Moved Database
helpcsharpdatabaseasp-netsql-server
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.
  • A Offline
    A Offline
    Aviv Halperin
    wrote on last edited by
    #1

    Hi, I have the following problem: I downloaded Microsoft sql server 2000 MSDE Service pack 3 (sql2ksp3). Then I installed it with the command line : setup SECURITYMODE=SQL SAPWD="sa" Next I tried to open a connection to a database from an ASP.NET using C#. I tried to use the following to connect: OleDbConnection conn = new OleDbConnection(@"Provider=SQLOLEDB;User ID=sa;Initial Catalog=master;Data Source=(local);"); conn.Open(); this failed with the error:Login failed for user 'sa' then I tried this: OleDbConnection conn = new OleDbConnection(@"Provider=SQLOLEDB;Integrated Security=SSPI;User ID=sa;Initial Catalog=master;Data Source=(local);"); conn.Open(); this failed with the error :Login failed for user 'HOME-35NVKYBV8B' were 'HOME-35NVKYBV8B' is my local host name Now the conn.Open(); allways gets the following error: Please help me if you have an answer.I've read every possible doc I could find but could not find the answer! Thanks. avivhal

    G 1 Reply Last reply
    0
    • A Aviv Halperin

      Hi, I have the following problem: I downloaded Microsoft sql server 2000 MSDE Service pack 3 (sql2ksp3). Then I installed it with the command line : setup SECURITYMODE=SQL SAPWD="sa" Next I tried to open a connection to a database from an ASP.NET using C#. I tried to use the following to connect: OleDbConnection conn = new OleDbConnection(@"Provider=SQLOLEDB;User ID=sa;Initial Catalog=master;Data Source=(local);"); conn.Open(); this failed with the error:Login failed for user 'sa' then I tried this: OleDbConnection conn = new OleDbConnection(@"Provider=SQLOLEDB;Integrated Security=SSPI;User ID=sa;Initial Catalog=master;Data Source=(local);"); conn.Open(); this failed with the error :Login failed for user 'HOME-35NVKYBV8B' were 'HOME-35NVKYBV8B' is my local host name Now the conn.Open(); allways gets the following error: Please help me if you have an answer.I've read every possible doc I could find but could not find the answer! Thanks. avivhal

      G Offline
      G Offline
      Grimolfr
      wrote on last edited by
      #2

      In your first example, OleDbConnection conn = new OleDbConnection(@"Provider=SQLOLEDB;User ID=sa;Initial Catalog=master;Data Source=(local);");, you didn't provide a password for the 'sa' account. But in your statement about how you installed MSDE, you said that you set the password to 'sa'. So, for this connection string, you should add Password=sa;. However, it is recommended that you not use a system administrator account to connect to the database from an application. In your second example, you are using integrated security, which means that the connection is made to the database using the currently active Windows login. I assume from the username in the error message, and your statement that it's the machine name, that you're writing a service, and it's set up to run using the system account. This would work, but you'll have to use a tool (or write an app) to configure the database server to allow this account to login, and give it access to the specific database that it needs to access. Note that since you set Integrated Security=SSPI;, the User Id=sa; part of the connection string is ignored.


      Grim

      (aka Toby)

      MCDBA, MCSD, MCP+SB

      Need a Second Life?[^]

      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