how can i change the path of the database from which i retrive data on run time....
i mean if the database is shifted from server to any othe location the how can the path of the database can be shifted.....

Dani AI

Generated

For : the usual, reliable pattern is to keep the database location out of hard-coded source and let the application rebuild or replace the connection string at startup (or when the location changes). pointed toward adjusting the connection at runtime; that idea works well when combined with one central storage location (app config, user setting, or a small settings file) and a short validation step before accepting a new path.

A minimal VB.NET workflow: read a stored path, build the provider/connection string, try to open the connection, and if it succeeds persist the new path. Example (VB.NET):

Dim dbPath As String = "C:\data\mydb.accdb"
Dim connStr As String = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=False;", dbPath)

Using cn As New System.Data.OleDb.OleDbConnection(connStr)
    Try
        cn.Open()
        ' valid - save to settings
        My.Settings.DatabasePath = dbPath
        My.Settings.Save()
    Catch ex As Exception
        ' log or handle: file missing, permission, provider not installed
    End Try
End Using

Notes and common pitfalls: when using typed DataSets/TableAdapters update their runtime connection (for example myAdapter.Connection.ConnectionString = connStr) so generated code does not keep an old value. Use UNC paths for network files (mapped drives can disappear for services). On Access files check provider compatibility (Jet vs ACE) and process bitness (x86 vs x64). Always test the new connection before saving and include clear error handling for permissions, missing drivers, or network issues.

Background on connection-string formats and best practices is documented by Microsoft: ADO.NET connection strings.

Mentions: , .

Recommended Answers

All 3 Replies

u need to frame the connection string at runtime.
but for that connection should not be opened.

can do that for ex at form load.

how can i change the path of the database from which i retrive data on run time....
i mean if the database is shifted from server to any othe location the how can the path of the database can be shifted.....

Mayank, please see the thread

Read Me: Access to any type of DB's Possible

that I have started. It will clear all your doubt.

regards
AV Manoharan

how can i change the path of the database from which i retrive data on run time....
i mean if the database is shifted from server to any othe location the how can the path of the database can be shifted.....

Mayank, please see the thread

Read Me: Access to any type of DB's Possible

that I have started. It will clear all your doubts.

regards
AV Manoharan

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.