Re: Opening a SQL Server 2005 Database...
- From: "Norman Yuan" <FakeName@xxxxxxxxxxxxx>
- Date: Mon, 3 Nov 2008 13:43:43 -0700
1. *.mdf is not database, it is data file used by SQL Server/Express. so "Initial Catalog=..." in ConnectionString should be a valid database name, not database file name;
2. You MUST understand what is USER INSTANCE in SQL Server Express. If you do not know, study on it, or donot use it;
3. The database file name (*.mdf) only used in ConnectionString with "AttachDBFileName=..."
"Rafael Soteldo" <RafaelSoteldo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:23FAAC93-3956-401E-B4A8-61A7F68F35D3@xxxxxxxxxxxxxxxx
Hi there:
I'm trying to open a SQL Server 2005 Database without creating a Data
Source, but I receive a login error message.
My code looks like:
SqlConnection conn = new SqlConnection(@"Data
Source=.\SQLExpress;Integrated Security=true;Initial
Catalog=MyDatabase.mdf;User Instance=true");
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM MyDatabase.Dbo.Alumnos", conn);
DataTable dtAlumnos = new DataTable();
da.Fill(dtAlumnos);
When I execute it from a Windows App, I receive the following error message:
"Cannot open database "MyDatabase.mdf" requested by the login. The login
failed.
Login failed for user 'MyMachineName\Rafael'."
It is strange since my user 'Rafael' has administrator priviledges, it's not
a limited account in windows. The database exists in SQL Server, when I open
it from the SQL Server Management Studio Express or from the Server Explorer,
it opens just fine.
I tried closing the SQL Server management Studio Express before executing
the code, but got the same result.
If I create an ASP.NET app, add the database to App_Data folder, and use the
following connection string: "Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated
Security=True;User Instance=True", it opens fine, but I understand that in
this case, the app is working with a private copy of the Database. not the
original one.
Can anybody tell me what am I missing here?
--
Rafael Soteldo
.
- References:
- Opening a SQL Server 2005 Database...
- From: Rafael Soteldo
- Opening a SQL Server 2005 Database...
- Prev by Date: Re: How do I to make a Script avoid being blocked by popup blocker
- Next by Date: Re: Opening a SQL Server 2005 Database...
- Previous by thread: Opening a SQL Server 2005 Database...
- Next by thread: Re: Opening a SQL Server 2005 Database...
- Index(es):
Relevant Pages
|
Loading