1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Server path to access databse

Discussion in 'C#' started by Sushi_Master, Nov 8, 2005.

  1. #1
    Hi all. I'm in need of help with this one. (see code below)

    The file connects to an access database to populate drop down boxes.

    This all works fine when tested on my local personal web server. Now i

    need to get this online but I can't get it to worlk.

    I have tried this code;

    var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & 
    
    Server.MapPath("FAQS.mdb")
    Code (markup):
    This did not work and all i get is a 500 server error. Can anyone see

    where im going wrong or where the problem lies? :confused: My server

    can handle asp and my database is in the same folder as my asp file. I

    can supply the database if anyone needs it.

    Many thanks in advance for any help.


    <%@ language = "Javascript" %>
    <%
    
    var strQuestion = "";
    if (Request.Querystring("stateChanged") == "true")
    {
    strQuestion = Request.Form("cboQuestion");
    }
    var strconnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data 
    
    Source=C:/testfolder/databases/FAQS.mdb";
    %>
    <script language=Javascript>
    function initControls()
    {
    populateQuestion();
    populateType();
    }
    function populateQuestion()
    {
    <%
    var rs = Server.CreateObject("ADODB.Recordset");
    var sql = "select distinct Question from tblQuestions order by Question"
    rs.Open(sql,strconnection);
    var n=0;
    while (!rs.EOF)
    {
    var stateID = rs.Fields("Question");
    var stateDesc = rs.Fields("Question");
    Response.Write("document.frmTest.cboQuestion[" + n + "] = new Option('" 
    
    + stateDesc+ "','" + stateID + "');");
    
    if (new String(strQuestion).search(stateID) != -1)
    
    Response.Write("document.frmTest.cboQuestion[" + n + "].selected = 
    
    true;");
    rs.MoveNext();
    n++;
    }
    rs.Close();
    %>
    }
    
    function populateType()
    {
    <%
    if (strQuestion != "")
      {
    	var rs2 = Server.CreateObject("ADODB.Recordset");
    	var strSql = "select distinct SubQuestion from tblQuestions 
    
    where Question = '" + strQuestion + "' ";
    	rs2.Open(strSql,strconnection);
    	var n=1;
    	while (!rs2.EOF)
    		{
    			var strType = rs2.Fields("SubQuestion");
    			
    
    Response.Write("document.frmTest.cboSubQuestion[" + n + "] = new 
    
    Option('" + strType + "','" + strType + "');");
    			rs2.MoveNext();
    			n++;
    		}
    		rs2.Close();
    	}
    %>
    }
    function fillType()
    	{
    		document.frmTest.action = 
    
    "contact-sam3.asp?stateChanged=true";
    		document.frmTest.submit();
    	}
    		function saveData()
    	{
    		document.frmTest.action = "./contact-sam3.asp";
    		return true;
    	}
    
    </script>
    
    <html>
    <head>
    <title>Multi Dropdown Selecting Value from one second will Display its 
    
    corresponding values</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-- Fireworks MX Dreamweaver MX target.  Created Tue Aug 19 09:32:36 
    
    GMT+0500 (West Asia Standard Time) 2003-->
    <script language="javascript">
    <!--
    
    function dept_onchange(frmTest) {
    	frmTest.submit(); 
    }
    
    //-->
    </script>
    
    </head>
    <body onload = "initControls();" bgcolor="#ffffff" link="#666666" 
    
    vlink="#666666" alink="#666666" leftmargin="0" topmargin="0">
    <table width="780" border="0" align="center" cellpadding="0" 
    
    cellspacing="0">
      <!-- fwtable fwsrc="index.png" fwbase="default.jpg" 
    
    fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="1" -->
      <tr>
       <td>
          <table border="0" cellpadding="0" cellspacing="0" width="780">
            <tr> 
              <td>&nbsp;</td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
       <td><table border="0" cellpadding="0" cellspacing="0" width="780">
    	  <tr>
    	      <td valign="top">
                <table width="220" border="0" cellpadding="0" 
    
    cellspacing="0" bgcolor="#D6E6F3">
                  <tr> 
                    <td valign="top" bgcolor="96C2DD"> <strong 
    
    style="font-weight: 400"> 
                      <font face="Verdana, Arial, Helvetica, sans-serif" 
    
    size="2" color="#FFFFFF"> 
                      Question &amp; SubQuestion</font></strong></td>
                  </tr>
                  <tr> 
                    <td valign="top"> 
                      <form name="frmTest" method="post" 
    
    action="contact-sam3.asp">
                        <table width="220" border="0" cellpadding="0" 
    
    cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
                          <tr valign="top" bgcolor="#D6E6F3"> 
                            <td height="25" colspan="2" width="220"> 
                              <select name="cboQuestion" 
    
    onChange="fillType()">
                                <option value="Select Question" 
    
    selected>Select Question</option>
                              </select>
                            </td>
                          </tr>
                          <tr bgcolor="#D6E6F3"> 
                            <td width="153" valign="top" bgcolor="#D6E6F3"> 
                              <SELECT name=cboSubQuestion 
    
    LANGUAGE=javascript onchange="return dept_onchange(frmTest)">
    						  <option value="Select 
    
    Question" selected>Select Question</option>
    						  </select>
                            </td>
                            <td width="67" bgcolor="#D6E6F3"> 
                              <INPUT TYPE = "Submit" VALUE = "GO>>>>">
                            </td>
                          </tr>
                        </table>
                      </form>
                    </td>
                  </tr>
                </table>
              </td>
    	      <td align="right">&nbsp; </td>
    	  </tr>
    	</table></td>
      </tr>
    </table>
    The following was selected : <%=Request.Form ("cboSubQuestion")%>
    </body>
    </html>
    Code (markup):
     
    Sushi_Master, Nov 8, 2005 IP
  2. daredashi

    daredashi Well-Known Member

    Messages:
    667
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    120
    #2
    it seems problem with absolute and relative paths.
    can you post link ?
    try using odbc dsn. many times web host deny use o relative paths (i.e use od "." or ".." in paths)
     
    daredashi, Nov 8, 2005 IP
  3. maro

    maro Peon

    Messages:
    356
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Is the mdb file in the same folder as the asp file? If not then you should point to it correctly in
    Server.MapPath("FAQS.mdb")
     
    maro, Nov 8, 2005 IP
  4. Sushi_Master

    Sushi_Master Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Read my thread again Maro :rolleyes:

    Thanks for trying to help :)
     
    Sushi_Master, Nov 8, 2005 IP
  5. murugan

    murugan Peon

    Messages:
    165
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi,

    Use the below connection string,

    Dim oConn
    Set oConn = Server.CreateObject("ADODB.Connection")
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath(".") & "mydatabase.mdb;"


    NOTE :
    (i) Replace mydatabase.mdb with actual database name and give read / write permission to your .mdb file.
    (ii) Uncheck "Show friendly HTTP Error Messages" in your browser to see the exact error message instead of "500 Internal Server Error"
     
    murugan, Nov 8, 2005 IP
  6. Sushi_Master

    Sushi_Master Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the help. I tried this out but I got an error. I think if the connection is made this way it effects the script used to populate the drop down boxes. Here is the error i got.

    Microsoft JScript compilation error '800a03ec' 
    
    Expected ';' 
    
    /contact-sam3.asp, line 9 
    
    Dim oConn
    ----^
    Code (markup):
    Thanks
     
    Sushi_Master, Nov 8, 2005 IP
  7. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #7
    you're designating javascript, not VBscript, which is why murugan's example isn't working for you. VBscript doesn't require the ";", while javascript does. I don't know javascript as well as I do VBscript, so i'm sorry i can't provide any examples of properly formatted JScript code to replace his example with, all i know is that's why you're getting this particular error.
     
    vectorgraphx, Nov 8, 2005 IP
  8. Sushi_Master

    Sushi_Master Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks vector!

    Anyone got any knowledge on how this can be corrected?

    Thanks, Sam
     
    Sushi_Master, Nov 8, 2005 IP
  9. Sushi_Master

    Sushi_Master Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Finally got it fixed. Thank you all for your help and advice. Very much appreciated.

    Right on the money with that vector! :D

    -Sam
     
    Sushi_Master, Nov 8, 2005 IP
  10. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #10
    awesome - glad ya sorted it out!
     
    vectorgraphx, Nov 8, 2005 IP