VBScript如何设置连接字符串
我不确定之前是否已经讨论过,但我有以下代码(我从 Access 数据库的示例中进行了更改。)
我不知道要在 'Provider' 中放入什么内容 和“数据源”。我正在使用 MS SQL Server 2005,如何在我的计算机中查找此信息?拜托,即使我尝试从这里开始http://www.connectionstrings.com/< /em>,但我还是不知道该怎么做。
Dim conn, sql
sql = "SELECT * FROM tblOutbox"
Set conn = CreateObject("ADODB.Connection")
With conn
.Provider = "myProvider"
.Mode = adModeReadWrite
.ConnectionString = "Data Source=mysource;" & _
"database=myDbase.mdf; "
.Open
End With
If conn.State = adStateOpen Then
WScript.Echo "Connection was established."
End If
conn.Close
Set conn = Nothing
这里使用access数据库:
Dim conn
Dim sql
sql = "SELECT * FROM tblOutbox"
Set conn = CreateObject("ADODB.Connection")
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = adModeReadWrite
.ConnectionString = "Data Source= f:/Status.mdb"
.Open
End With
WScript.Echo "Connection was opened."
conn.Close
Set conn = Nothing
WScript.Echo "Connection was closed."
I am not sure whether it has been disscussed before or not but I have the following code (I changed from example for an Access database.)
I don't know what to put inside the 'Provider' and the 'Data Source'. I'm using MS SQL Server 2005 and how to find this information in my machine? Please, even I try to follow from here http://www.connectionstrings.com/, yet I still don't know how to do it.
Dim conn, sql
sql = "SELECT * FROM tblOutbox"
Set conn = CreateObject("ADODB.Connection")
With conn
.Provider = "myProvider"
.Mode = adModeReadWrite
.ConnectionString = "Data Source=mysource;" & _
"database=myDbase.mdf; "
.Open
End With
If conn.State = adStateOpen Then
WScript.Echo "Connection was established."
End If
conn.Close
Set conn = Nothing
here is using access database:
Dim conn
Dim sql
sql = "SELECT * FROM tblOutbox"
Set conn = CreateObject("ADODB.Connection")
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Mode = adModeReadWrite
.ConnectionString = "Data Source= f:/Status.mdb"
.Open
End With
WScript.Echo "Connection was opened."
conn.Close
Set conn = Nothing
WScript.Echo "Connection was closed."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试在连接字符串中设置提供程序
注意:我还没有测试过它,但它应该可以工作
Try setting the provider in the connection string
Note: I haven't tested it but it should work
满足您所有的连接字符串需求:http://www.connectionstrings.com/
For all your connection string needs: http://www.connectionstrings.com/
感谢您的帮助,我终于找到了解决方案。
在“管理工具”、“数据源 (ODBS)”、“驱动程序”选项卡下,我使用提供程序:SQLNCLI、我的服务器:数据源,并将 Recordset rs 添加到代码中。看来,没有这个,连接就建立不起来。我不知道发生了什么事。
I finally found the solution thanks to your help.
Under the Administrative Tools, Data Source (ODBS), driver tabs, I use provider: SQLNCLI, my Server: Data Source, and I add Recordset rs to the code. It seems that, without this one, the connection is not established. I don't know what happened.
使用 SQL Server,您不直接连接到该文件。 Access 作为基于文件的 RDBMS 略有不同。
按照你的例子,它看起来像这样:
通常有一种更紧凑的方法来做到这一点,但如果没有上下文,很难给出更好的例子
With SQL Server you don't connect directly to the file. Access, being a file-based RDBMS is a little different.
Following your example, it would look something like this:
There's usually a more compact way of doing this, but without the context its hard to give a better example