Re: Opening a SQL Server 2005 Database...



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

.



Relevant Pages

  • RE: Accessing SqlServer(Express) data on the server
    ... As for the ASP.NET, it is built upon the .net framework, so generally all ... you can change the connectionstring to point to another ... manually create another database (named "MyASPNETDB" in SQL Express ... you can even use SQL Server authentication(specify username/password ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: MS Access DAO -> ADO.NET Migration
    ... William Vaughn ... Microsoft MVP ... Hitchhiker's Guide to Visual Studio and SQL Server ... My migration app works building a SSCE database file with imported data ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Cluster will not fail over.
    ... > As far as the TCP/IP issue goes, you had to rebuild the cluster and were ... > able to restore the master database. ... > a cluster installation you'll have to revisit. ... >> This worked bringing up the sql server in minimal mode. ...
    (microsoft.public.sqlserver.clustering)
  • Re: MS Access DAO -> ADO.NET Migration
    ... full SQL Server and I see the logic you explained in a multi user ... allow two users to access the same database file Read/Write at any given ... The book was a pleasure to read after the gibberish that Microsoft 'puts ... Hitchhiker's Guide to Visual Studio and SQL Server ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: MS Access DAO -> ADO.NET Migration
    ... For that it is much harder to handle the incremental identifier, ... database but although they have the data, they are not connected at the same ... The book was a pleasure to read after the gibberish that Microsoft 'puts ... SQL Server Management Studio is nowhere to be found on my ...
    (microsoft.public.dotnet.framework.adonet)

Loading