Trouble to connect to database

Results 1 to 3 of 3

Thread: Trouble to connect to database

  1. #1
    Gösta Jönsson Guest

    Default Trouble to connect to database

    I have a database in Acces CalendarEvents with year,month,day and a Deskription. I can connect with a connectionstring set to "DSN=CalendarEvents" and use a SQL-query strSQL SELECT Day, Description FROM Events WHERE Month = " & Month(dbCurrentDate) &_ AND Year = "& Year(dbCurrentDate) & " ORDER BY day ASC.<BR>IF I use objConn.ConnectionString="DRIVER={Microsoft Access Driver(*.mdb)}; "& "DBQ=c:my documentsCalendarEvents.mdb" I can´t connect properly to my database. What am i doing wrong. The fault is in the connection string and isn´t due to typos. It seems that I must add some info because i use SQL. I dont know which, and i need detailed info. Would be very grateful for a working exemple of a connectionstring. It is a modified problem of bonusproject 3 n Active Server Pages 3.o

  2. #2
    Join Date
    Dec 1969

    Default RE: Trouble to connect to database

    &#060;%<BR>&#039 Declare our variables... always good practice!<BR>Dim cnnSimple &#039 ADO connection<BR>Dim rstSimple &#039 ADO recordset<BR>Dim strDBPath &#039 path to our Access database (*.mdb) file<BR><BR><BR>&#039 MapPath of virtual database file path to a physical path.<BR>&#039 If you want you could hard code a physical path here.<BR>strDBPath = Server.MapPath("db_scratch.mdb")<BR><BR><BR>&#039 Create an ADO Connection to connect to the scratch database.<BR>&#039 We&#039re using OLE DB but you could just as easily use ODBC or a DSN.<BR>Set cnnSimple = Server.CreateObject("ADODB.Connection")<BR><BR>&#0 39 This line is for the Access sample database:<BR>cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"<BR><BR>&#039 Execute a query using the connection object. It automatically<BR>&#039 creates and returns a recordset which we store in our variable.<BR>Set rstSimple = cnnSimple.Execute("SELECT * FROM scratch")<BR><BR><BR>&#039 Display a table of the data in the recordset. We loop through the<BR>&#039 recordset displaying the fields from the table and using MoveNext<BR>&#039 to increment to the next record. We stop when we reach EOF.<BR>%&#062;

  3. #3
    Gösta Jönssn Guest

    Default RE: Trouble to connect to database

    Thank You very much indeed!Works like wonder.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts