---
title: "Hur gör jag..."
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/5900-hur-gör-jag"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Sammy"
published: "2000-06-21T07:38:00.000Z"
updated: "2000-06-22T07:49:00.000Z"
replies: 4
views: 276
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/5900-hur-gör-jag"
---

# Hur gör jag...

## #1 — Sammy, 2000-06-21T07:38Z

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...

Permalänk: https://www.webforum.nu/p/5900

## #2 — rymdknark, 2000-06-21T10:43Z

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

Permalänk: https://www.webforum.nu/p/243815

## #3 — Sammy, 2000-06-22T05:03Z

Och det ersätter jag med?

Permalänk: https://www.webforum.nu/p/243816

## #4 — rymdknark, 2000-06-22T06:16Z

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")

Permalänk: https://www.webforum.nu/p/243817

## #5 — Sammy, 2000-06-22T07:49Z

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

Testade genast och det verkar fungera bra..

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

Permalänk: https://www.webforum.nu/p/243818

---

Tråden på webben: https://www.webforum.nu/amne/asp/5900-hur-gör-jag
