ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

Attach Database

  • 描述
  • 使用方法
  • 语法
  • 代码示例
  • 环境
  • 许可信息

描述

Attaches a .mdf file to an instance of SQL Server Express. This creates a geodatabase from the input .mdf file. Detach and attach allow you to move geodatabases between instances of SQL Server Express.

Use attach and detach to transfer geodatabases from one SQL Server Express instance to another. After the geodatabase has been detached from one instance, it can be attached to a different instance of SQL Server Express.

使用方法

  • Attaching a geodatabase to a database server registers the data file with the SQL Server Express instance. The geodatabase is added to the server and appears in the Catalog tree.

  • You must have Full Control over the folder to attach the .mdf file to the SQL Server instance.

  • The .mdf file must be located on the same computer as the SQL Server Express.

  • You must be a server administrator and a Windows administrator on the machine where SQL Server Express is installed to attach a geodatabase to a database server.

  • The attached geodatabase will have the same name as it did on the instance from which it was detached. If you try to attach a geodatabase to SQL Server Express that already has a geodatabase with the same name, the operation will fail.

  • Users, schemas, and data remain in the transferred database. If the users who own data in the database do not exist on the database server to which the database is transferred, you need to add them.

  • Use the Create Database Connection tool to create a connection file from the outputs of this tool.

  • This tool will attempt to start the SQL Express instance if it is stopped.

语法

arcpy.production.AttachDatabase(server_name, mdf_file_path)
参数说明数据类型
server_name

The name of the SQL Server instance to which the .mdf file will be attached.

String
mdf_file_path

The path to the .mdf file.

File

代码示例

AttachDatabase example (stand-alone script)

The following stand-alone script demonstrates how to use the AttachDatabase tool.

# Name: AttachDatabase_Example.py
# Description: Attaches a SQL Server Express geodatabase (.mdf file) to an instance of SQL Server
# Requires: Production Mapping extension

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("Foundation")

# Local variables:
Server_Name = "YOUR_SERVER_NAME\\SQLEXPRESS"
Product_Library_mdf = "C:\\Data\\Product_Library.mdf"
Data = "C:\\Data"

# Database_Name = "Product_Library"
Database_Platform = "SQL_SERVER"

# Attach Database
Database_Name = arcpy.AttachDatabase_production(Server_Name, Product_Library_mdf)
print (Database_Name)

# Process: Create Database Connection
ProductLibrary_Workspace = arcpy.CreateDatabaseConnection_management(Data, Database_Name, Database_Platform, Server_Name, "OPERATING_SYSTEM_AUTH", "", "*****", "SAVE_USERNAME", Database_Name, "", "TRANSACTIONAL", "dbo.DEFAULT", "")

print (ProductLibrary_Workspace)
arcpy.CheckInExtension("Foundation")

环境

  • 当前工作空间

许可信息

  • Basic: 否
  • Standard: 需要 Production Mapping
  • Advanced: 需要 Production Mapping

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明