Avatar billede Laitings Nybegynder
21. maj 2002 - 12:05 Der er 8 kommentarer og
1 løsning

Access forbindelses fejl!?

Jeg har følgende kode som er en søgefunktion i en access database:

<%
intPage = Request("page")
If isNumeric(intPage) = False Or intPage < 1 Then
    intPage = 1
End If
Set rs = Server.CreateObject("ADODB.RecordSet")
'Søgning opbygges
strSQL = "select * from [PersonTabel] WHERE "

' normale indtastnings felter og dropdowns 
Felt = split("Fornavn,Efternavn,Email",",")

for i = 0 to 2 ' 2 er det antal felter der står i Felt - 1
    if request(Felt(i)) <> "" then
        strSQL = strSQL & "[" & Felt(i) & "] like '%" & request(Felt(i)) & "%' and "
        tmpFound = true
    end if
next

If request("alder") = "" Then
strSQL = strSQL & "[Alder] BETWEEN 1 and 99 Order By Fornavn"
End if

'variabler overføres
Fornavn = Request("Fornavn")
Efternavn = Request("Efternavn")

strDSN = "DSN = ""DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/database/db.mdb") & ""
rs.Open strSQL, strDSN, 1
If Not (rs.BOF Or rs.EOF) Then
    rs.PageSize = 10
    rs.AbsolutePage = intPage
    intRecCount = rs.PageSize
    intPageCount = rs.PageCount
%>


Men jeg får følgende fejl når jeg forsøger at få forbindelse til databasen:

Microsoft OLE DB Service Components (0x80040E73)
Format of the initialization string does not conform to the OLE DB specification.

Fejlen ligger i denne linje: rs.Open strSQL, strDSN, 1
men problemet ligger i denne linje: strDSN = "DSN = ""DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/database/db.mdb") & ""

Hvordan kommer jeg uden om det problem?

Håber på hjælp!
Avatar billede pfp Nybegynder
21. maj 2002 - 12:09 #1
Du kan da ikke bare have en SQL der ser sådan ud:
strSQL = "select * from [PersonTabel] WHERE "

Du skal jo have din WHERE sætning til at være lig noget. F.eks.

strSQL = "select * from [PersonTabel] WHERE=" & Request.Querystring("person")

/peter
Avatar billede Slettet bruger
21. maj 2002 - 12:09 #2
("/database
("database
Avatar billede Laitings Nybegynder
21. maj 2002 - 12:14 #3
SQl sætningen bliver lavet i "for"-løkken, men jeg VED at det fungerer. Problemet er heller ikke i /database.

Problemet ligger i den måde jeg laver rs.Open strSQL, strDSN, 1 på denne linje: strDSN = "DSN = ""DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/database/db.mdb") & ""

Før i tiden så den linje sådan ud: strDSN ="DSN=Nyt_DSN" som var en DSN jeg havde på min egen comp. Men nu ligger databasen på et webhotel og det betyder jeg er nødt til at bruge server.mapPath
Avatar billede teamdev Novice
21. maj 2002 - 12:21 #4
set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.open(Server.Mappath("database/db.mdb")
Avatar billede teamdev Novice
21. maj 2002 - 12:22 #5
istedet for strdsn
Avatar billede Laitings Nybegynder
21. maj 2002 - 12:33 #6
Nu ser koden således ud:

<%
intPage = Request("page")
If isNumeric(intPage) = False Or intPage < 1 Then
    intPage = 1
End If
Set rs = Server.CreateObject("ADODB.RecordSet")
'Søgning opbygges
strSQL = "select * from [PersonTabel] WHERE "

' normale indtastnings felter og dropdowns 
Felt = split("Fornavn,Efternavn,Email",",")

for i = 0 to 2 ' 2 er det antal felter der står i Felt - 1
    if request(Felt(i)) <> "" then
        strSQL = strSQL & "[" & Felt(i) & "] like '%" & request(Felt(i)) & "%' and "
        tmpFound = true
    end if
next

If request("alder") = "" Then
strSQL = strSQL & "[Alder] BETWEEN 1 and 99 Order By Fornavn"
End if

'variabler overføres
Fornavn = Request("Fornavn")
Efternavn = Request("Efternavn")

set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"   
    conn.open(Server.Mappath("/Roskildeny/database/roskilde.mdb"))
'strDSN = "DSN = ""DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/Roskildeny/database/roskilde.mdb") & ""
rs.Open strSQL, 1
If Not (rs.BOF Or rs.EOF) Then
    rs.PageSize = 10
    rs.AbsolutePage = intPage
    intRecCount = rs.PageSize
    intPageCount = rs.PageCount
%>

men jeg får følgende fejl:

Error Type:
ADODB.Recordset (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.


i denne linje: rs.Open strSQL, 1

What's going on!?!?
Avatar billede teamdev Novice
21. maj 2002 - 12:40 #7
I denne linie er jeg ikke sikker på at der skal [] omkring alder

strSQL = strSQL & "[Alder] BETWEEN 1 and 99 Order By Fornavn"

ditto for
strSQL = strSQL & "[" & Felt(i) & "] like '%" & request(Felt(i)) & "%' and "

her er det bare & felt(i)

Prøv desuden
rs.Open "& strSQL &", conn, 3, 1, 1
Avatar billede Laitings Nybegynder
21. maj 2002 - 12:46 #8
Superfedt TeamDev! Du er for hård!

Denne her virkede: rs.Open strSQL, conn, 3, 1, 1

Hvis det ikke er alt for besværligt, ku du så ikke forklare hvad, 3, 1, 1 betyder!?

Tak!

-Mescalito
Avatar billede tjacob Juniormester
21. maj 2002 - 15:20 #9
-Klippet fra MSDN:

recordset.Open Source, ActiveConnection, CursorType, LockType, Options

Parameters

Source  Optional. A Variant that evaluates to a valid Command object variable name, an SQL statement, a table name, a stored procedure call, or the file name of a persisted Recordset.

ActiveConnection  Optional. Either a Variant that evaluates to a valid Connection object variable name, or a String containing ConnectionString parameters.

CursorType  Optional. A CursorTypeEnum value that determines the type of cursor that the provider should use when opening the Recordset. Can be one of the following constants (see the CursorType property for definitions of these settings).

Constant Description
adOpenForwardOnly (Default) Opens a forward-only–type cursor.
adOpenKeyset Opens a keyset-type cursor.
adOpenDynamic Opens a dynamic-type cursor.
adOpenStatic Opens a static-type cursor.


LockType  Optional. A LockTypeEnum value that determines what type of locking (concurrency) the provider should use when opening the Recordset. Can be one of the following constants (see the LockType property for more information).

Constant Description
adLockReadOnly (Default) Read-only—you cannot alter the data.
adLockPessimistic Pessimistic locking, record by record—the provider does what is necessary to ensure successful editing of the records, usually by locking records at the data source immediately upon editing.
adLockOptimistic Optimistic locking, record by record—the provider uses optimistic locking, locking records only when you call the Update method.
adLockBatchOptimistic Optimistic batch updates—required for batch update mode as opposed to immediate update mode.


Options  Optional. A Long value that indicates how the provider should evaluate the Source argument if it represents something other than a Command object, or that the Recordset should be restored from a file where it was previously saved. Can be one of the following constants (see the CommandType property for a more detailed explanation of the first five constants in this list).

Constant Description
adCmdText Indicates that the provider should evaluate Source as a textual definition of a command.
adCmdTable Indicates that ADO should generate an SQL query to return all rows from the table named in Source.
adCmdTableDirect Indicates that the provider should return all rows from the table named in Source. 
adCmdStoredProc Indicates that the provider should evaluate Source as a stored procedure.
adCmdUnknown Indicates that the type of command in the Source argument is not known.
adCommandFile Indicates that the persisted (saved) Recordset should be restored from the file named in Source. 
adExecuteAsync Indicates that the Source should be executed asynchronously.
adFetchAsync Indicates that after the initial quantity specified in the CacheSize property is fetched, any remaining rows should be fetched asynchronously. 

Jeg er ikke helt sikker på hvilken talværdi konstanterne har, men jeg vil
tro det er noget i denne retning for din forbindelse:

rs.Open "& strSQL &", conn, adOpenDynamic, adLockReadOnly, adCmdText
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester