Support & FAQ
Support & FAQ
 
 

Support & FAQ

Spørgsmål:

Database forbindelse (MS-SQL)

Svar:

Eksemplet nedenfor viser hvordan forbindelsen til en MS-SQL database etableres.

<html>
<head>
<title>Database forbindelse</title>
</head>
<body>

<%
Set Conn = Server.Createobject("ADODB.Connection")

' --- Database forbindelse ---
strDBConn = "Provider=sqloledb;" & _
"Data Source= 194.255.126.XX ,1433;" & _
"Network Library=DBMSSOCN;" & _
"Initial Catalog= dXXXXXXX ;" & _
"User ID= uXXXXXXX ;" & _
"Password= XXXXXXX ;"

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>

 

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>

 

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>

 

Eksempel: ODBC


<html>
<head>
<title>Database forbindelse</title>
</head>
<body>

<%
Set Conn = Server.Createobject("ADODB.Connection")

'
--- Database forbindelse ---
strDBConn = "DRIVER={SQL Server};" &_
"Address= 194.255.126.XX
,1433;" &_
"UID= uXXXXXXX ;password= XXXXXXXX
;" &_
"Network=DBMSSOCN;" &_
"DATABASE= dXXXXXXX
;" &_
"SERVER= 194.255.126.XX ;"

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>


Eksempel:

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>


Eksempel:

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>


Eksempel:

Conn.Open strDBConn

' --- SQL forespørgelse ---
Set RS = Conn.Execute("SELECT * FROM Kunder")
%>

<table border="1" width="400">
<%
' --- Udskriv data ---
Do While Not RS.EOF
%>
<tr>
<td><%=RS("ID")%></td>
<td><%=RS("Navn")%></td>
<td><%=RS("Adresse")%></td>
</tr>
<%
RS.MoveNext
Loop

RS.close
Conn.Close
Set RS = nothing
Set Conn = nothing

%>
</table>

</body>
</html>

Eksempel:

1 Jens Hansen Nørregade 45, 8000 Århus C
2 Lise Thomsen Skolegade 3, 5000 Odense


Hvordan ville du karakteriserer dette indhold (hvor 5 er bedst)?


Senest opdateret: 10-11-2008, 13:33.
A/S ScanNet - Birkemose Allé 11 - 6000 Kolding - Tlf. (+45) 75 53 35 00 - Fax (+45) 75 53 35 09 - scannet@scannet.dk