Now many friends are using sql2008, but the original 2000 code can no longer be used. Here I will share the method of connecting ASP to sql2008. Friends who need it can refer to it.
Although there are many introductions online, it still took a lot of effort for me to connect. (IIS and SQL SERVER need to be installed)
Create a new *.asp file and type
Copy the code code as follows:<%
set conn =server.createobject(adodb.connection)
conn.open provider=sqloledb;source=local;uid=sa;pwd=******;database=database-name
%>
Among them, don’t worry about the one after provider, just write it as written; the one after source can be the IP address, here I use the local one; sa is built-in
User, its password is set during installation; database is followed by the name of the database you want to connect to, for example: mydatabase
(No extension required).
Once connected, you can operate the database.
The following is an example of transferring information through a form (FORM) and saving it to the database.
HTML file:
Copy the code code as follows:<html>
<body>
<form name=Form action=*.asp method=post>
<input name=Name type=text><br>
<input name=Password type=password><br>
<input type=submit>
</form>
</body>
</html>
ASP file: (The file name is the same as *.asp after the action above and is saved in the same path)
Copy the code code as follows:<%
dimsql
sql =select * from table-name
set conn=server.createobject(adodb.connection)
conn.open provider=sqloledb;source=local;uid=sa;pwd=*******;database=db-name
set rs=server.createobject(adodb.recordset)
rs.open sql,conn,3,2
rs.addnew
rs(name)=request.form(Name)
rs(pwd)=request.form(Password)
rs.update
%>