连接字符串错误
Windows Server 2003 上的 IIS 出现问题(使用经典的 ASP Web 应用程序) 数据库服务器 (SQL Server 2005) 位于同一台计算机上。
我创建一个记录集,并按如下方式设置其活动连接:
Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=xxx.xxx.xxx.xxx,1433;Initial Catalog=mydatabase;User ID=myusername;Password=mypassword;"
问题是,当我设置此连接字符串时,会出现以下错误:
参数类型错误,超出可接受的范围,或者与一个冲突其他。
我知道这个连接字符串没有问题,因为当我使用我的开发服务器,但将连接指向远程数据库时,它工作得很好。
我尝试了许多连接字符串变体(来自connectionstrings.com),但他们给出了相同的错误。
Having a problem with IIS on Windows Server 2003 (using a classic ASP web application)
The database server (SQL Server 2005) is on the same machine.
I create a recordset, and set its activeconnection as follows:
Dim RS
Set RS = Server.CreateObject("ADODB.Recordset")
RS.ActiveConnection = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=xxx.xxx.xxx.xxx,1433;Initial Catalog=mydatabase;User ID=myusername;Password=mypassword;"
The problem is that as SOON as I set this connection string, the following error is raised:
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I know there isnt a problem with this connection string because when I use my development server, but point the connection toward the remote database, it works great.
I have tried many MANY connection string variations (from connectionstrings.com) and they have given the same error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ActiveConnection
属性采用ADODB.Connection
类型的对象,而不是字符串。您不能直接分配连接字符串,您需要分配数据库连接。您的代码需要如下所示:实际上您根本不应该以这种方式使用
ActiveConnection
属性,您实际应该使用它来断开记录集以避免保持数据库连接打开不必要地:The
ActiveConnection
property takes an Object of typeADODB.Connection
and not a String. You can't assign a Connection String directly, you need to assign a database connection. Your code needs to look like the following:Actually you shouldn't really use the
ActiveConnection
property in this way at all, what you should actually use it for is disconnecting a recordset to avoid keeping the database connection open unecessarily:@RobV - 创建连接对象并将其分配给记录集确实是一个选项,但是,快捷方式是将连接字符串分配给记录集 - 这确实有效。
事实上,以下代码是最有效的:
我不确定我收到的错误发生了什么,但它突然停止了,没有更改任何代码!
@RobV - Creating a connection object and assigning that to the recordset is indeed an option, however, a shortcut to this is assigning a connection string to the recordset - which does work.
In fact the following code is the most efficient:
Im not sure what happened with the error I was getting but it SUDDENLY just stopped without having changed any code!
尝试执行类似于 MSDN 示例 的操作。
它单独创建一个连接,然后分配它。
Try doing something similar to this MSDN Sample.
It's creating a connection separately, then assigning it.