How to code DATA SOUCE

Discussion in 'Databases' started by findcausene, Feb 23, 2008.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. findcausene

    findcausene chas28

    [​IMG]?ve spent the last few months going crazy trying to write a connection string to allow me to insert information into my database. The database called ?capsDb1.mdb is located in my app_data file. The following code which points to a copy of the database on my ?C:? drive works well
    Data Source= " &amp; C:/capsDb1.mdb")</o:p>
    However, when I point to a copy of the database in my app_data file locate in the visual studio 2005 project file I get an error message.</o:p>
    Data Source= " &amp; ("~/App_Data/capsDb1.mdb")</o:p>
    Error msg: </o:p>
    'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\~\App_Data\capsDb1.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides</o:p>
    As far as I can tell this is a valid path. Can any one help me or tell me where I can go to get help?</o:p>
    Charlie
     
  2. Connecting to an access DB with ASP.NET or classic asp you do best to use a path method.
    Shown below is a successful ASP.NET connect I used here to an access DB.
    If you need specific help let me know, no problem at all.
    Salute,
    Mark


     
  3. findcausene

    findcausene chas28

    Thank you for your help, but I still can?t get the code to work. When I try the following code:
    </o:p>
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath("../App_Data/capsDb1.mdb")</o:p>
    </o:p>
    Or this code:
    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath("../_database/capsDb1.mdb")</o:p>
    </o:p>
    </o:p>
    I get an error message:
    </o:p>
    Server Error in '/bin' Application. </o:p>



    'E:\web\findcausene\htdocs\bin\.._database\capsDb1.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. </o:p>
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: 'E:\web\findcausene\htdocs\bin\.._database\capsDb1.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

    Source Error: </o:p>




    </o:p>
    Line 14: </o:p>
    Line 15: conCID = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath(".._database/capsDb1.mdb"))</o:p>
    Line 16: conCID.Open()</o:p>
    Line 17: '</o:p>
    Line 18: ' cmdSelectCID = New OleDbCommand("Select[CID] FROM [Characteristics Table] Order by [CID] Desc", conCID)</o:p>

    Source File: E:\web\findcausene\htdocs\bin\Test1.aspx.vb Line: 16

    Stack Trace: </o:p>




    </o:p>
    [OleDbException (0x80004005): 'E:\web\findcausene\htdocs\bin\.._database\capsDb1.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.]</o:p>
    System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1131233</o:p>
    System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53</o:p>
    System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27</o:p>
    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47</o:p>
    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105</o:p>
    System.Data.OleDb.OleDbConnection.Open() +37</o:p>
    Test1.Page_Load(Object sender, EventArgs e) in E:\web\findcausene\htdocs\bin\Test1.aspx.vb:16</o:p>
    System.Web.UI.Control.OnLoad(EventArgs e) +99</o:p>
    System.Web.UI.Control.LoadRecursive() +47</o:p>
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436</o:p>
    </o:p>



    </o:p>
    I?ve spent over a day trying to debug this problem. What is the next step.?</o:p>
    </o:p>
    Charlie</o:p>
     
  4. Joseph Jun

    Joseph Jun DiscountASP.NET Staff

    Greetings Charlie,

    Keep in mind that Server.MapPath simply maps a path to the actual physical path on the server. You won't have to include the '..' to specify going up a directory but by including the '..' as part of the path, you're telling the application that the database is in a directory called, E:\web\findcausene\htdocs\bin\.._database\, which doesn't exist.

    All you really should need to do to resolve the problem is update your code to the following:

    Server.MapPath('/_database/sample.mdb')

    Winston

    DiscountASP.NET
     
  5. Oops, my bad...Not sure why I put those path climbers there, must have been groggy. [​IMG]
    Good catch!
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page