数据库配置的示例代码(MSDE) [英] Example code for database configuration(MSDE)

查看:78
本文介绍了数据库配置的示例代码(MSDE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道我在哪里可以找到VB.NET的示例代码我可以使用

创建一个应用程序,使用

osql scipts将数据库附加到MSDE并将其分离到MSDE 。

(我认为通常使用SQL-DMO)


提前致谢

解决方案

您好


下面显示了附加数据库的示例。
http://support.microsoft.com/?id=224071


以下显示了osql的参数实用程序。
http://msdn.microsoft.com/library/de..._osql_1wxl.asp


John


大卫 <哒*** @ orbitcoms.com>在留言中写道

news:lu ******************* @ news-server.bigpond.net.au ...

有谁知道我在哪里可以找到VB.NET的示例代码,我可以使用
创建一个应用程序,使用osql scipts将数据库附加到MSDE
并将其分离。
(我认为通常使用SQL-DMO)

提前致谢



添加到约翰的回复另一种方法是直接从你的应用程序执行sp_attach_db

,而不是外壳到OSQL。示例

以下。

Public Shared Sub AttachDb(_

ByVal ConnectionString As String,_

ByVal DatabaseName As字符串,_

ByVal FileList As String())

尝试

Dim connection As New SqlConnection(ConnectionString)

connection.Open()

Dim命令As New SqlCommand(" sp_attach_db",connection)

command.CommandType = CommandType.StoredProcedure


command.Parameters.Add(_

新SqlParameter(" @ dbname",DatabaseName))

Dim fileNumber As Integer

Dim fileName As String

For fileNumber = 1 To FileList.Length

command.Parameters.Add(_

New SqlParameter (String.Format(" @filename {0}",

fileNumber.ToString),_

FileList(fileNumber - 1)))

下一个fileNumber


command.ExecuteNonQuery()

connection.Close()


Catch ex As SqlExceptio n $ / b $ b抛出新的ApplicationException(附加数据库失败: + _

ex.ToString())

结束尝试


结束子


-

希望这会有所帮助。


Dan Guzman

SQL Server MVP


大卫 <哒*** @ orbitcoms.com>在留言中写道

news:lu ******************* @ news-server.bigpond.net.au ...

有谁知道我在哪里可以找到VB.NET的示例代码,我可以使用
创建一个应用程序,使用osql scipts将数据库附加到MSDE
并将其分离。
(我认为通常使用SQL-DMO)

提前致谢



Dan,


感谢您的回复。在你附上之前我注意到你使用

数据库名称进行连接。

这是系统数据库之一(Master,TempDb ....)?,就像这样点

我们还没有附上感兴趣的数据库?


谢谢

Dan Guzman <哒******* @ nospam-earthlink.net>在消息中写道

news:qD *************** @ newsread1.news.pas.earthlin k.net ...

要添加到John的响应,另一种方法是直接从您的应用程序执行sp_attach_db
而不是外壳到OSQL。示例
下面。

公共共享子AttachDb(_
ByVal ConnectionString As String,_
ByVal DatabaseName As String,_
ByVal FileList As String( ))

尝试
Dim连接为新的SqlConnection(ConnectionString)
connection.Open()
Dim命令As New SqlCommand(" sp_attach_db",connection)< br。> command.CommandType = CommandType.StoredProcedure

command.Parameters.Add(_
New SqlParameter(" @ dbname",DatabaseName))
Dim fileNumber As Integer
Dim fileName As String
for fileNumber = 1 To FileList.Length
command.Parameters.Add(_
New SqlParameter(String.Format(" @filename {0}" ,
fileNumber.ToString),_
FileList(fileNumber - 1)))
下一个fileNumber

command.ExecuteNonQuery()
con nection.Close()

Catch ex As SqlException
抛出新的ApplicationException(" Attach database failed:" + _
ex.ToString())
结束尝试

结束子

- 希望这会有所帮助。

Dan Guzman
SQL Server MVP

大卫 <哒*** @ orbitcoms.com>在消息中写道
新闻:lu ******************* @ news-server.bigpond.net.au ...

有谁知道我在哪里可以找到VB.NET的示例代码,我可以使用
创建一个应用程序,使用

osql将数据库附加到MSDE


scipts。
(我认为通常使用SQL-DMO)

提前致谢




Does anyone know where I can find example code for VB.NET that I can use
to create an application that attaches and detaches databases to MSDE using
osql scipts.
(I think SQL-DMO is typically used)

Thanks in advance

解决方案

Hi

The following shows example of attaching a database.
http://support.microsoft.com/?id=224071

The following shows the parameters to the osql utility.
http://msdn.microsoft.com/library/de..._osql_1wxl.asp

John

"David" <da***@orbitcoms.com> wrote in message
news:lu*******************@news-server.bigpond.net.au...

Does anyone know where I can find example code for VB.NET that I can use
to create an application that attaches and detaches databases to MSDE using osql scipts.
(I think SQL-DMO is typically used)

Thanks in advance



To add to John''s response, another method is to execute sp_attach_db
directly from your application rather than shelling out to OSQL. Example
below.
Public Shared Sub AttachDb( _
ByVal ConnectionString As String, _
ByVal DatabaseName As String, _
ByVal FileList As String())

Try
Dim connection As New SqlConnection(ConnectionString)
connection.Open()
Dim command As New SqlCommand("sp_attach_db", connection)
command.CommandType = CommandType.StoredProcedure

command.Parameters.Add( _
New SqlParameter("@dbname", DatabaseName))
Dim fileNumber As Integer
Dim fileName As String
For fileNumber = 1 To FileList.Length
command.Parameters.Add( _
New SqlParameter(String.Format("@filename{0}",
fileNumber.ToString), _
FileList(fileNumber - 1)))
Next fileNumber

command.ExecuteNonQuery()
connection.Close()

Catch ex As SqlException
Throw New ApplicationException("Attach database failed: " + _
ex.ToString())
End Try

End Sub

--
Hope this helps.

Dan Guzman
SQL Server MVP

"David" <da***@orbitcoms.com> wrote in message
news:lu*******************@news-server.bigpond.net.au...

Does anyone know where I can find example code for VB.NET that I can use
to create an application that attaches and detaches databases to MSDE using osql scipts.
(I think SQL-DMO is typically used)

Thanks in advance



Dan,

Thanks for the reply. I notice before you attach, you connect using a
database name.
Is this one of the system databases (Master,TempDb....) ?, as at this point
we have not attached the db of interest ?

Thanks
"Dan Guzman" <da*******@nospam-earthlink.net> wrote in message
news:qD***************@newsread1.news.pas.earthlin k.net...

To add to John''s response, another method is to execute sp_attach_db
directly from your application rather than shelling out to OSQL. Example
below.
Public Shared Sub AttachDb( _
ByVal ConnectionString As String, _
ByVal DatabaseName As String, _
ByVal FileList As String())

Try
Dim connection As New SqlConnection(ConnectionString)
connection.Open()
Dim command As New SqlCommand("sp_attach_db", connection)
command.CommandType = CommandType.StoredProcedure

command.Parameters.Add( _
New SqlParameter("@dbname", DatabaseName))
Dim fileNumber As Integer
Dim fileName As String
For fileNumber = 1 To FileList.Length
command.Parameters.Add( _
New SqlParameter(String.Format("@filename{0}",
fileNumber.ToString), _
FileList(fileNumber - 1)))
Next fileNumber

command.ExecuteNonQuery()
connection.Close()

Catch ex As SqlException
Throw New ApplicationException("Attach database failed: " + _
ex.ToString())
End Try

End Sub

--
Hope this helps.

Dan Guzman
SQL Server MVP

"David" <da***@orbitcoms.com> wrote in message
news:lu*******************@news-server.bigpond.net.au...

Does anyone know where I can find example code for VB.NET that I can use
to create an application that attaches and detaches databases to MSDE


using

osql scipts.
(I think SQL-DMO is typically used)

Thanks in advance




这篇关于数据库配置的示例代码(MSDE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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