AttachDB Method (SQL-DMO)

The AttachDB method makes a database visible to a Microsoft® SQL Server™ installation.

Applies To

SQLServer Object

Syntax

object.AttachDB( DBName , DataFiles ) as String

Part Description
object Expression that evaluates to an object in the Applies To list
DBName String specifying an existing database by name
DataFiles SQL-DMO multistring specifying operating system files by name

Returns

A string indicating success or failure.

Remarks

The AttachDB method is used when a change to the location of operating system files implementing the database must be made visible to the SQL Server installation.

The DataFiles argument can specify up to 16 operating system files. Each file should be specified by complete name, including the path. At least one file in the list of those specified must be the PRIMARY data file. Operating system files implementing storage for the transaction log can be specified.

The AttachDB method fails if more than 16 operating system files are specified. When using SQL-DMO to move a database implemented on more than 16 files, use the CreateForAttach property of a Database object.

Making a database visible to a SQL Server installation by using the AttachDB method requires appropriate privilege. The SQL Server login used for SQLServer object connection must be a member of the system-defined role sysadmin.

Prototype (C/C++)

HRESULT AttachDB(SQLDMO_LPCSTR DBName,
SQLDMO_LPCSTR DataFiles,
SQLDMO_LPBSTR pResult);

See Also

CreateForAttach Property

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.