<% Option Explicit %>
<%
Dim strConn,conn
strConn="provider=SQLOLEDB; data source=localhost;INITIAL CATALOG=personal;User ID=sa; Password="
set conn=server.createobject("adodb.connection")
conn.open strConn
%>
เจอ Error แบบนี้ครับ
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
ODBC
ไปตั้งค่า dns แล้วนะครับ Code (ASP)
<% Option Explicit %>
<html>
<head>
<title>ThaiCreate.Com ASP & SQL Server Tutorial</title>
</head>
<body>
<%
On Error Resume Next '*** Not Show ASP Error ***'
Dim Conn1
Set Conn1 = Server.Createobject("ADODB.Connection")
Conn1.Open "Driver={SQL Server};Server=localhost;Database=personal;UID=sa;PWD=;"
If Err.Number <> 0 Then
Response.write("(SQL Server Driver) Database cannot connect Error = " & Err.Description&"<br>")
Else
Response.write("(SQL Server Driver) Database connected.<br>")
End If
Conn1.Close()
Set Conn1 = Nothing
Dim Conn2
Set Conn2 = Server.Createobject("ADODB.Connection")
Conn2.Open "personal","sa",""
If Err.Number <> 0 Then
Response.write("(ODBC) Database cannot connect Error = " & Err.Description&"<br>")
Else
Response.write("(ODBC) Database connected.<br>")
End If
Conn2.Close()
Set Conn2 = Nothing
%>
</body>
</html>
Error ที่เจอ
(SQL Server Driver) Database cannot connect Error = [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
(ODBC) Database cannot connect Error = [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
login โดย sa ได้ปกติครับ ตอนนี้สามารถต่อกับ sql ได้แล้วแต่ odbc ยังไม่ได้ครับ ยังขึ้น ODBC) Database cannot connect Error = [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
รึว่าลองลบ Space Bar หน้า Data Source กับ Password ดู
strConn = "Provider=SQLOLEDB;Data Source=LocalHost;User ID=sa;Initial Catalog=Personal;Password="