المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : database connection error with sa user in SQL Express 2005



C# Programming
04-15-2010, 10:32 AM
I've got 2 connection strings:

1. "Data Source=.\SQLEXPRESS;
User Id=sa;Password=hello;
AttachDbFilename=C:\inetpub\wwwroot\MySite\dbs\MyDb.mdf;
Connect Timeout=30" 2. "Data Source=.\SQLEXPRESS;
AttachDbFilename=C:\inetpub\wwwroot\MySite\dbs\MyDb.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True"
2nd is working perfectly for db connection,
but using 1st returns that error:

System.Data.SqlClient.SqlException:
Unable to open the physical file "C:\inetpub\wwwroot\MySite\dbs\MyDb.mdf".
Operating system error 5: "5(Access Denied)".
An attempt to attach an auto-named database for file
C:\inetpub\wwwroot\MySite\dbs\MyDb.mdf failed.
A database with the same name exists,
or specified file cannot be opened,
or it is located on UNC share.
In SQL Server COnfiguration Manager I enabled all services
and protocols - SQL Server (SQLEXPRESS), SQL Server Browser,
Shared Memory, Named Pipes, TCP/IP, VIA.

In SQL Server Management Studio Express sa/hello user is present
and Server Properties->Security - SQL Server and Windows Authentication mode
If I put incorrect password in 1st connection string it reports password error.

Here is the code to connect to db and get some records just for a sake:
SqlConnection con = new SqlConnection(this.connection);
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
int nRows = da.Fill(ds, "Persons");
????????