Showing posts with label attach. Show all posts
Showing posts with label attach. Show all posts

Friday, March 9, 2012

Fail to attach to MDF file

I tried to use sp_attach_single_file_db to attach to a MDF file which is probably corrupted in a power failure. But, whenever I run this stored procedure, I get some error message like
Change language setting to us_english
Server: msg 945, Level 14, State 2, line 1
Database 'AlbumSQL' can not be opened because some of the files could not be activated.
Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'AlbumSQL'. CREATE DATABASE is aborted.
There is also a Ldf file in the same folder, but when I tried to use sp_attach_db, I get the other message
Server: Msg 5172, Level 16, State 15, Line 1
The header for file 'd:\data\albumsql_log.ldf' is not a valid database file header. The PageAudit property is incorrect.
Can you help me some hint to solve this problem? Thanks.
-Alex HuangIS it possible that there is more than one data file.. Attach single file db
only works when there is only one data file... (Based on the error message,
that kind of sounds like it might be happening.)
Otherwise it is probably time to open a call to PSS>
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Alex Huang" <alexh@.ulead.com> wrote in message
news:3DBA8115-8DCC-4853-8ED5-F53B15619452@.microsoft.com...
> I tried to use sp_attach_single_file_db to attach to a MDF file which is
probably corrupted in a power failure. But, whenever I run this stored
procedure, I get some error message like
> Change language setting to us_english
> Server: msg 945, Level 14, State 2, line 1
> Database 'AlbumSQL' can not be opened because some of the files could not
be activated.
> Server: Msg 1813, Level 16, State 2, Line 1
> Could not open new database 'AlbumSQL'. CREATE DATABASE is aborted.
> There is also a Ldf file in the same folder, but when I tried to use
sp_attach_db, I get the other message
> Server: Msg 5172, Level 16, State 15, Line 1
> The header for file 'd:\data\albumsql_log.ldf' is not a valid database
file header. The PageAudit property is incorrect.
> Can you help me some hint to solve this problem? Thanks.
> -Alex Huang

fail to attach a database

I am trying to attach a database, but get access error. here is what I did:

(1) I installed the microsoft sql server 2005 express and sql server management studio express on my pc (vista).

(2) I imported a database called myCompany.mdf, saved in the Microsoft SQL Server/MSSQL.1/MSSQL/Data directory, all users (including myself mary-PC\mary) allowed with full control.

(3) Attach database using microsoft SQL server management studio express -> right click Database -> Attach -> attachDatabase windown pop up -> click Add..-> give me the following error:

TITLE: Microsoft SQL Server Management Studio Express

Failed to retrieve data for this request. (Microsoft.SqlServer.Express.SmoEnum)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&LinkId=20476


ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.Express.ConnectionInfo)

The server principal "mary-PC\mary" is not able to access the database "model" under the current security context. (Microsoft SQL Server, Error: 916)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.3042&EvtSrc=MSSQLServer&EvtID=916&LinkId=20476


BUTTONS:

OK

I am the admin of this PC and can see the database and log files in the /data directory with full permission, but why can't I attach the databae file to the sql server? can someone help? thanks,

You probably need to explicitly add "mayre-PC\mary" as a sysadmin on the SQL Server. Setup will add the Windows Administrators group to the sysadmin role, but with Vista User Account Control, the individual accounts need to be explicitly provisioned to sysadmin.