webForumDet fria alternativet

Hur gör jag...

ASP

4 svar · 253 visningar · startad av Sammy

Medlem sedan maj 2000202 inlägg
Frågan#1

Vilka förändringar behöver jag göra för att öppna databasen DSN-lös i detta:

<%
' Declaring variables
Dim email, con, data_source, sql_insert, sql_check, rs

email = Request.Form("email")
' Check that email address is empty or not. If email address
' is not empty then continue, otherwise redirect the user back to
' the main page

If Len(email) Then

' Note you can add your database's DSN here if you want
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("mail.mdb")
' Our SQL statements
sql_check = "select email from users where email = '" & email & "'"
sql_insert = "insert into users( email ) values ('" & email & "')"

' Lets first check to see if the email address is alread present in
' the database. Create the instance of Connection Object and then
' open the database

Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source

Set rs = con.Execute (sql_check, , 1)

' If email address is not present then add it to the database
If rs.EOF Then

con.Execute sql_insert
' Displaying the result of successful entry to the user
Response.Write "Thank you. Your email address <b>" & email & _
"</b> was successfully entered into the database"
' But if email address is already present then display it to
' the user

Else
Response.Write "Your email address " & email & _
" is already present in the database. Thank you."
End If

' Done. Disconnecting and setting Connection Object to Nothing
con.Close
Set con = Nothing

' And if the email address submitted was empty Then
Else
Response.Redirect "default.asp"
End If
%>

Jag vill alltså öppna och använda databasen utan en DSN-koppling.

Tacksam för svar...

------------------
/Sammy Swärd

Medlem sedan maj 2000175 inlägg
#2

conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("databas.mdb")

Medlem sedan maj 2000202 inlägg
#3

Och det ersätter jag med?

------------------
/Sammy Swärd

Medlem sedan maj 2000175 inlägg
#4

istället för:
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("mail.mdb")

så skriver du:
data_source = "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("mail.mdb")

Medlem sedan maj 2000202 inlägg
#5

Ah.. det var inte svårare än så?

Testade genast och det verkar fungera bra..

Tack för din hjälp.. den uppskattar jag!

------------------
/Sammy Swärd

258 ms totalt · 4 externa anrop · v20260731065814-full.e96017d9
123 ms — deklarationer (db)
0 ms — hämta statistik (cache)
129 ms — hämta tråd, inlägg och bilagor (db)
125 ms — ändringar (db)