Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

sql server - How to connect to a sql database using classic asp?

Could someone please help solve this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's a simple script that you can use:

<%

Dim conn

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Northwind; User Id = sa; Password="

If conn.errors.count = 0 Then

Response.Write "Connected OK"

End If

%>

And a def of the connection string members:

  • Provider: The provider value tells ADO which data provider it should call to give us access to the data that we need. "SQLOLEDB" is the best provider to use for Microsoft SQL Server 2000 databases. If we left out the provider value, then ADO would automatically default to the "MSDASQL" provider, which is Microsoft’s OLEDB provider for ODBC compatible data repositories.
  • Data Source: The data source value tells our provider the IP Address or netbios name of the computer on which our database is available. In our example above, I have used the value "(local)". This value tells the provider that our database resides on the local machine, and to use local procedure calls instead of remote procedure calls. Using this data source value makes data access faster because database function calls are not bounced across the network and back to the SQL Server like they are normally.
  • Initial Catalog: The initial catalog value is just a fancy name for the database that the provider should connect us to by default.
  • User Id: The login Id of the SQL Server user account that the provider should use during the authentication process.
  • Password: The password of the SQL Server use account that the provider should use during the authentication process.

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...