21. maj 2002 - 12:05Der 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
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") & ""
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
<% 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
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:
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.