如何创建使用SMO本地数据库实例 [英] How to create local database Instance using SMO

查看:187
本文介绍了如何创建使用SMO本地数据库实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了localdatabase并创建了一个共享实例,并使用SMO我能够创造localdatabase。

I have installed localdatabase and created a shared instance, and using smo I am able to create localdatabase.

有关我的要求我必须创建的LocalDB共享实例。

For my requirement I have to create a localdb shared instance.

我创建使用SMO这样的本地数据库。

I am creating local database using SMO like this.

ServerConnection serConn = new ServerConnection(@"(localdb)\.\sharedIns");
Server ldbServer = new Server(serConn);

Database db = new Database(ldbServer , "databaseName");
db.Create();

在创建数据库之前,我通过命令提示符下使用sqllocaldb.exe这样创建共享实例

Before creating database, I am creating shared instance through command prompt using sqllocaldb.exe like this

c:\>sqllocaldb create testIns
c:\>sqllocaldb share testIn sharedIns

我想删除这些手动步骤并创建的LocalDB使用SMO共享实例。如何做到这一点?

I want to remove these manual steps and create localdb shared instance using SMO. How to do this?

推荐答案

我认为封装底层的LocalDB原生API,露出一个接口的开源.NET库它允许你这样做这种事情。详情请参见以下链接:

I maintain an open-source .NET library that wraps the underlying LocalDB native API, exposing an interface that allows you do this this kind of thing. See the below links for more detail:

  • SQL LocalDB Wrapper on GitHub
  • SQL LocalDB Wrapper on NuGet

问候,

马丁

这篇关于如何创建使用SMO本地数据库实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆