我正在使用MS SQL Server Management Studio2014。使用链接服务器,我可以将Excel File链接为链接服务器。我知道如何连结。但是我想知道如何在链接服务器上链接5个Excel文件,或者我必须为每个excel文件创建单独的链接服务器?
提前致谢,
您可以使用OLEDB提供程序或ODBC驱动程序提供程序进行设置,并使用服务器上的ODBC管理器工具创建与Excel文件的连接。
如果您想定期读取Excel文件,则此方法非常有用。
另外,您可以使用VBA代码使用SQL Server管理对象SMO将Excel数据源配置为链接服务器。
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s As Server
Dim conn As ServerConnection
Dim ls As LinkedServer
conn = New ServerConnection("ServerName\InstanceName", "YourUesrName", "YourPassword")
s = New Server(conn)
Try
ls = New LinkedServer(s, "XLTEST_DMO")
With ls
.ProviderName = "Microsoft.Jet.OLEDB.4.0"
.ProductName = "Excel"
.DataSource = "c:\book1.xlsx"
.ProviderString = "Excel 9.0"
End With
ls.Create()
MessageBox.Show("New link has been created.")
Catch ex As SmoException
MessageBox.Show(ex.Message)
Finally
ls = Nothing
If s.ConnectionContext.IsOpen = True Then
s.ConnectionContext.Disconnect()
End If
End Try
End Sub
End Class
希望对您有所帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句