ASP-based MSSQL connection methods and Common Errors
// Method 1:
Mm_conn_string = "driver = {SQL Server}; server = (local); uid = sa; Pwd =; database = infs ;"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open mm_conn_string
Set rs = server. Createobject ("adobd. recordset ")
SQL = "select * from Table order by ID DESC"
Rs. Open SQL, Conn, 3, 3
// Method 2: (DSN connection)
Mm_conn_string = "DSN = BBS; uid = sa; Pwd = 12345"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open mm_conn_string
Set rs = server. Createobject ("adobd. recordset ")
SQL = "select * from Table order by ID DESC"
Rs. Open SQL, Conn, 3, 3 // 3, 3 is to change, delete, add switch!
// Method 3:
Mm_conn_string_own = "driver = {SQL}; server = (local); uid = sa; Pwd = 11111; database = infs ;"
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open mm_conn_string_own
// Method 4-this method is used in access
Strconn = "driver = Microsoft Access Driver (*. mdb); DBQ = "_
& Server. mappath ("ASP. mdb ")
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open strconn
Method 1:
<%
Dim Conn
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "provider = sqloledb; Data Source = (local); uid = user name; Pwd = password; database = Database"
Set conn = server. Createobject ("ADODB. Connection ")
Dsntemp = "driver = {SQL Server}; server = (local); uid = user name; Pwd = password; database = Database"
Conn. Open dsntemp
%>
Method 2:
<%
Option explicit
Dim startime
Dim Conn
Dim connstr
Dim dB, pass_word, user_id, data_source
Startime = timer ()
DB = "database name"
Pass_word = "account password"
User_id = "Logon account"
Data_source = "service name or IP"
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = sqloledb.1; Password = '" & pass_word & "'; persist Security info = true; user id = '" & user_id &"'; initial catalog = '"& dB &"'; Data Source = '"& data_source &"'"
Conn. Open connstr
Function closedb
Conn. Close
Set conn = nothing
End Function
Common Faults
()
Microsoft ole db provider for ODBC drivers fault '80040e57'
[Microsoft] [odbc SQL Server Driver] [SQL Server] string or binary data wocould be truncated.
This is because the number of fields in the database table is too small.
(B)
Error reminder:
Microsoft ole db provider for ODBC drivers fault '80040e57'
[Microsoft] [odbc SQL Server Driver] [SQL Server] Arithmetic
Overflow error for data type smallint, value = 32768.
Because the field type is smallint too small, it should be changed to int.
(C)
Icrosoft ole db provider for ODBC drivers fault '80040e4d'
[Microsoft] [odbc SQL Server Driver] [SQL Server] login failed for user 'user78 '.
/Index333.asp, row 30
The username or password of the database is incorrect.
(D)
Microsoft ole db provider for ODBC drivers error '20140901'
[Microsoft] [ODBC driverProgramManager] the data source name is not invented and the default driver is not specified
/include/Conn. ASP, Row 3
the reason for this phenomenon is: 1. the Web server does not correctly set the data source.
you must provide the host name and database IP address, send a letter to liveperson, and set up a data source on the server for normal calls.