使用SQL-DMO来操控SQL服务器

来源:互联网 发布:win8电脑优化 编辑:程序博客网 时间:2024/05/24 22:45
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

SQL的分布式关系对象(SQL-DMO)库允许你的VB6应用程序自动地同SQL服务器进行交互操作。这对于获取关于SQL服务器的信息很有用,例如服务器的状态或者网络上的可用服务器.

要使用SQL-DMO库,就要设置一个对“微软SQL-DMO对象库”的参照。

Application对象的ListAvailableSQLServers方法会返回一个NameList对象,它包含有网络上可用服务器的列表。下面的代码显示了一个使用这个方法来填充列表框控件的方法:

Dim objSQLApp As SQLDMO.Application
Dim objNameList As SQLDMO.NameList
Dim intCount As Integer

Set objSQLApp = New SQLDMO.Application

Set objNameList = objSQLApp.ListAvailableSQLServers()

For intCount = 1 To objNameList.Count
    Call List1.AddItem(objNameList.Item(intCount))
Next

SQL-DMO库里另外一个有用的对象是SQLServer对象。这个对象能够被用来获取关于特定SQL服务器的信息。Connect方法会建立到数据库服务器的连接并接受三个参数:数据库名、用户名和密码。一旦对象的连接成功了,关于服务器的信息就能够被取回:

Dim objSQLServer As SQLDMO.SQLServer

Set objSQLServer = New SQLDMO.SQLServer
objSQLServer.LoginSecure = True
Call objSQLServer.Connect("MyServerName", "username", "password")

Debug.PrintobjSQLServer.Name
Debug.PrintobjSQLServer.HostName
Debug.PrintobjSQLServer.Status


<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击