使用经典 asp 将数据库上下文更改为 'sqldbname' 错误
Changed database context to 'sqldbname' error with classic asp
对此有一些疑问,但就我而言 know/believe 他们根本帮不了我。我的代码之前运行良好。但不知为何停了下来。我的sql服务器版本是2012,具体报错是:
[Microsoft][ODBC SQL Server Driver][SQL Server] Changed database context to 'sqldbname'
我的ASP代码:
<!--#include file="connv.inc"-->
<%
n=Request.form("total")
response.write(n)
for x = 0 to n-1
ttitle=Request.form("title_"&x)
title=Replace(ttitle, "'", "''")
id=Request.form("id_"&x)
views=Request.form("vViews_"&x)
likes=Request.form("vLikes_"&x)
description=Request.form("vDescription_"&x)
sql="INSERT INTO tbl_videos(videoTitle, videoId, videoLikes, videoViews, videoDescription, swamCompatible) values ('"&title&"', '"&id&"', '"&likes&"', '"&views&"', '"&description&"', '0')"
connv.execute(sql)
response.write(sql&"<br>")
next
%>
<html>
<head>
<title> Updating Tables </title>
</head>
<body>
</body>
</html>
<!--#include file="closeEmv.inc"-->
connv.inc代码:
<%
set connv = server.createobject("ADODB.Connection")
connv.open "DRIVER={SQL SERVER}; SERVER=52.2.8.73; UID=myuid; PWD=mypwd; DATABASE=sqldbname"
%>
尝试用以下部分替换您的 connv.inc 代码,
<%
set connv = server.createobject("ADODB.Connection")
connv.open "Provider=SQLOLEDB; Data Source=52.2.8.73; Initial Catalog=sqldbname; User ID=myuid; Password=mypwd"
%>
以下一位来自
@JonathanLin You haven't fixed anything you have just switched one connection type for another. You were using SQL Server ODBC Driver this answer changes that to the Microsoft OLE DB Provider for SQL Server.
@JonathanLin It all depends on what version of SQL Server you are using if you are using SQL Server 2005 you should be using the SQL Native Client 9.0 OLE DB Provider or higher but after SQL Server 2000 you should be using a SQL Native Client OLE Provider to support types like nvarchar(max) for example (worth noting SQL Native Client 9.0 is backward compatible).
您应该尝试使用最新的提供程序,以平衡功能和向后兼容性(您没有说明您使用的 SQL 服务器的版本) 我建议使用 SQL Native Client 9.0 OLE DB Provider.
如果您的 Web 服务器上没有安装,您需要先 download 并安装它。
<%
Set connv = Server.CreateObject("ADODB.Connection")
connv.open "Provider=SQLNCLI; Server=myServerAddress; Database=myDataBase; Uid=myUsername; Pwd=myPassword;"
%>
使用此提供程序将确保您在从早期版本的 SQL 服务器升级时可以访问功能,而无需弄乱您的连接字符串。 NVARCHAR(MAX)
(最初由 SQL Server 2005 支持).
等功能
旁注:
此外,不要在 #include
文件中打开连接,而是考虑将连接字符串存储为字符串变量,并仅在需要时实例化 ADODB.Connection
。
事实上,当使用 ADODB.Command
执行 SQL 服务器命令时,连接字符串变量可以传递给命令对象的 ActiveConnection
属性 并且命令对象将实例化 ADODB.Connection
给你。这样当命令关闭时连接也会关闭。
对此有一些疑问,但就我而言 know/believe 他们根本帮不了我。我的代码之前运行良好。但不知为何停了下来。我的sql服务器版本是2012,具体报错是:
[Microsoft][ODBC SQL Server Driver][SQL Server] Changed database context to 'sqldbname'
我的ASP代码:
<!--#include file="connv.inc"-->
<%
n=Request.form("total")
response.write(n)
for x = 0 to n-1
ttitle=Request.form("title_"&x)
title=Replace(ttitle, "'", "''")
id=Request.form("id_"&x)
views=Request.form("vViews_"&x)
likes=Request.form("vLikes_"&x)
description=Request.form("vDescription_"&x)
sql="INSERT INTO tbl_videos(videoTitle, videoId, videoLikes, videoViews, videoDescription, swamCompatible) values ('"&title&"', '"&id&"', '"&likes&"', '"&views&"', '"&description&"', '0')"
connv.execute(sql)
response.write(sql&"<br>")
next
%>
<html>
<head>
<title> Updating Tables </title>
</head>
<body>
</body>
</html>
<!--#include file="closeEmv.inc"-->
connv.inc代码:
<%
set connv = server.createobject("ADODB.Connection")
connv.open "DRIVER={SQL SERVER}; SERVER=52.2.8.73; UID=myuid; PWD=mypwd; DATABASE=sqldbname"
%>
尝试用以下部分替换您的 connv.inc 代码,
<%
set connv = server.createobject("ADODB.Connection")
connv.open "Provider=SQLOLEDB; Data Source=52.2.8.73; Initial Catalog=sqldbname; User ID=myuid; Password=mypwd"
%>
以下一位来自
@JonathanLin You haven't fixed anything you have just switched one connection type for another. You were using SQL Server ODBC Driver this answer changes that to the Microsoft OLE DB Provider for SQL Server.
@JonathanLin It all depends on what version of SQL Server you are using if you are using SQL Server 2005 you should be using the SQL Native Client 9.0 OLE DB Provider or higher but after SQL Server 2000 you should be using a SQL Native Client OLE Provider to support types like nvarchar(max) for example (worth noting SQL Native Client 9.0 is backward compatible).
您应该尝试使用最新的提供程序,以平衡功能和向后兼容性(您没有说明您使用的 SQL 服务器的版本) 我建议使用 SQL Native Client 9.0 OLE DB Provider.
如果您的 Web 服务器上没有安装,您需要先 download 并安装它。
<%
Set connv = Server.CreateObject("ADODB.Connection")
connv.open "Provider=SQLNCLI; Server=myServerAddress; Database=myDataBase; Uid=myUsername; Pwd=myPassword;"
%>
使用此提供程序将确保您在从早期版本的 SQL 服务器升级时可以访问功能,而无需弄乱您的连接字符串。 NVARCHAR(MAX)
(最初由 SQL Server 2005 支持).
旁注:
此外,不要在 #include
文件中打开连接,而是考虑将连接字符串存储为字符串变量,并仅在需要时实例化 ADODB.Connection
。
事实上,当使用 ADODB.Command
执行 SQL 服务器命令时,连接字符串变量可以传递给命令对象的 ActiveConnection
属性 并且命令对象将实例化 ADODB.Connection
给你。这样当命令关闭时连接也会关闭。