我尝试了很多,但我无法处理这个问题。我最后2天浪费了没有任何重要结果。希望我会在这里得到一些帮助。使用asp连接到SQL Server 2008数据库
我想用ASP连接到SQL Server 2008数据库。我安装了SQL Server 2008,创建了一个数据库,但我无法使用asp代码连接到该数据库。我可以在Visual Web Developer中看到数据库,也可以使用Visual Web Developer的添加连接向导通过asp.net进行连接,但我不想使用添加连接向导。我想写我的asp代码连接到记事本中的SQL Server数据库。我的IIS正在工作,我能够运行asp代码来访问其他数据库,如MS访问数据库,但我无法访问SQL Server数据库。
SQL Server Management Studio中的对象资源管理器中显示:
localhost\SQLSERVER3(SQL Server 10.0.1600-RAJ-PC\raj)
数据库
examples
tables
System Tables
dbo.cars
columns
id(PK,int,not null)
name(varchar(50),null)
你可以看到所附jpg图片在SQL Server及其数据库。我想连接到示例数据库,然后想要访问汽车表。
请帮帮我。
修订
这里是我的代码:
<html>
<head>
<title>Guestbook</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsGuestbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "ODBC;Driver={SQL Native Client};" & _
"Server=localhost\SQLSERVER3;" & _
"Database=examples;" & _
"Uid=raj;" & _
"Pwd=love1987"
'Set an active connection to the Connection object using DSN connection
'adoCon.Open "DSN=guestbook"
'Create an ADO recordset object
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT name FROM dbo.cars;"
'Open the recordset with the SQL query
rsGuestbook.Open strSQL, adoCon
'Loop through the recordset
Do While not rsGuestbook.EOF
'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write (rsGuestbook("Name"))
'Response.Write ("<br>")
'Response.Write (rsGuestbook("Comments"))
'Response.Write ("<br>")
'Move to the next record in the recordset
rsGuestbook.MoveNext
Loop
'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>
C#或VB?你的代码到目前为止看起来如何? –
2件事。 1。您是否正在寻求ASP(经典)或ASP.NET的帮助。 2.你有没有一个你正在使用的代码样本来尝试连接到数据库以显示你已经尝试了什么? –
啊,你改变了默认实例吗? – ApolloSoftware