Problem connecting to sql with C# and ASP.NET
-
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
-
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
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 addPassword=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 setIntegrated Security=SSPI;
, theUser Id=sa;
part of the connection string is ignored.
Grim
(aka Toby)
MCDBA, MCSD, MCP+SB