Help, please. Can't connect to database

Results 1 to 2 of 2

Thread: Help, please. Can't connect to database

  1. #1
    Mark Taff Guest

    Default Help, please. Can't connect to database

    All,<BR><BR>I am very new to working with databases over the Web, and am attempting to teach myself how. I created a sample database in Access, then exported it to dbase (my host,, is a UNIX server running Chilisoft and they won&#039;t support Access databases) The dbase files are main.dbf and main.dbt. They are both located in the same directory as the asp page I am using to try and connect to them (<BR><BR>I have to use DSN-less connections. I took some code (VBScript)from an article here on 4Guys, modified it as I thought correct, but it won&#039;t work. Here is the code from test2.asp:<BR><BR>****Begin Code*****<BR>&#060;%@ LANGUAGE="VBSCRIPT" %&#062;<BR>&#060;HTML&#062;<BR>&#060;BODY&#062;<BR >&#060;% Response.Write("Hello, World!") %&#062;<BR>&#060;% Dim strX <BR>strX = "Is this going to work?"<BR>Response.Write ("<BR>&#060;B&#062;" & strX & "&#060;/B&#062;<BR>")<BR> <BR>&#039;declares strSQL and creates string with SQL command<BR>&#039;Dim strSQL<BR>&#039;strSQL = "SELECT * FROM main" <BR>&#039;Response.Write(strSQL) <BR><BR>&#039;creates database connection object<BR>Dim objConn<BR>Set objConn = Server.CreateObject("ADODB.Connection")<BR>Respons e.Write(objConn)<BR><BR>&#039;specifies DSN-less connection, if used. DBQ is path to database file;<BR>&#039;DRIVER specifies driver to use<BR>objConn.ConnectionString = "DBQ=u261/marktaff/main.dbf;DRIVER={ODBC dBase Driver (*.dbf)}"<BR><BR>&#039;opens connection to database<BR>objConn.Open<BR><BR>&#039;declares objRS and creates recordset object<BR>Dim objRS<BR>Set objRS = Server.CreateObject("ADODB.Recordset")<BR><BR>&#03 9;declares strSQL and creates string with SQL command<BR>Dim strSQL<BR>strSQL = "SELECT * FROM main" <BR>Response.Write(strSQL)<BR><BR>&#039;use the Recordset&#039;s Open method, telling the<BR>&#039;recordset the SQL string we want to execute and what<BR>&#039;database we are wanting to execute it on. <BR>objRS.Open strSQL, objConn <BR> <BR>&#039;test script to this point<BR>Response.Write ("step 1")<BR><BR><BR>%&#062; <BR>&#060;/BODY&#062;<BR>&#060;/HTML&#062;<BR>****End Code****<BR><BR>Any guidance would be very much appreciated. Thank you.<BR><BR>Mark Taff

  2. #2
    Join Date
    Dec 1969

    Default *MUST* use physical file name...

    In this line:<BR><BR>objConn.ConnectionString = "DBQ=u261/marktaff/main.dbf;DRIVER={ODBC dBase Driver (*.dbf)}" <BR><BR>You are not giving a *physical* file name (one that starts with a drive letter, C:, D:, etc.).<BR><BR>The usual solution is to do:<BR><BR>objConn.ConnectionString = "DBQ=" & Server.MapPath("u261/marktaff/main.dbf") _<BR>&nbsp; &nbsp; &nbsp; &nbsp; & ";DRIVER={ODBC dBase Driver (*.dbf)}" <BR><BR>But you need to understand how Server.MapPath works. Using the code as shown, the physical path you get will be *relative to the directory containing the current asp page*.<BR><BR>That is, if the ASP page is:<BR><BR>c:inetpubwwwrootmyappsomePage.asp<BR><B R>Then Server.MapPath("u261/marktaff/main.dbf")<BR><BR>will produce<BR><BR>c:inetpubwwwrootmyappu261marktaffma in.dbf<BR><BR>So you may want to experiment a little to get the right path!<BR><BR>Try doing:<BR><BR>&#060;%<BR>path = Server.MapPath("u261/marktaff/main.dbf")<BR>Response.Write "path is " & path & "&#060;HR&#062;" & vbNewLine<BR>objConn.ConnectionString = "DBQ=" & path & ";DRIVER={ODBC dBase Driver (*.dbf)}" <BR>...<BR>%&#062;<BR><BR>So you can actually see *exactly* what file the system is trying to use. If it is wrong, adjust the path given to Server.MapPath.<BR><BR>Experiment...<BR><BR><BR><B R>

Posting Permissions

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