为什么我的 asp.net 会导致运行时错误?
我正在尝试连接到本地服务器上的数据库。该数据库称为“dbtest”。当然,我已经放弃了我的实际密码,并将其替换为“password”。
这是我在每个教程中看到的典型代码,但它根本不起作用。请帮忙。
<%
Dim con, rs
con = Server.CreateObject("ADODB.Connection") 'I think it is something to do with this line
con.Open "Provider=sqloledb;SERVER=localhost;DATABASE=dbtest;UID=administrator; PWD=password;"
rs = Server.CreateObject("ADODB.Recordset")
%>
I am trying to connect to a database on my local server. The database is called "dbtest." Of course, I have left off my actual password and replaced it with "password."
This is the typical code I see on every tutorial, but it doesn't work at all. Please help.
<%
Dim con, rs
con = Server.CreateObject("ADODB.Connection") 'I think it is something to do with this line
con.Open "Provider=sqloledb;SERVER=localhost;DATABASE=dbtest;UID=administrator; PWD=password;"
rs = Server.CreateObject("ADODB.Recordset")
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是 ASP.NET。这是经典的 ASP
您必须首先阅读有关创建数据库驱动的 Web 应用程序的内容。
了解 SqlDataSource 和 GridView 控件。您不需要任何代码。
这里: http://www.asp.net/data-access/tutorials/querying-data-with-the-sqldatasource-control-cs" asp.net/data-access/tutorials/querying-data-with-the-sqldatasource-control-cs
This is not asp.net. This is classic ASP
You have to read about creating a database driven webapp first.
Read about SqlDataSource and GridView controls. You won't need any code.
here: http://www.asp.net/data-access/tutorials/querying-data-with-the-sqldatasource-control-cs
您正在学习的教程可能有点过时,.net 包含用于 SQL 数据访问的更新类,请查看此处
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.aspx
特别是在 SqlConnection 类和 SqlCommand 类中。
有一个有用的教程,可以在此处找到。
ADODB.Recordset 的等效项是 SqlDataReader 类。
The tutorials you are following may be a little out of date, .net includes updated classes for SQL data access, have a look here
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.aspx
Particularly at the SqlConnection class and SqlCommand class.
There is a useful tutorial that can be found here.
The equivalent of the ADODB.Recordset would be the SqlDataReader class.