How to query a remote MS ACCESS .mdb database using C# - c#

I am trying to use C# to query a mote MS ACCESS database .mdb file. I can successfully query it when copying the file to my local machine. I just want to put the file remotely, so my the client side program doesn't contain raw data.
static string m_path = "http://www.xyz.com/temp/";
static string m_connWords = "Provider=Microsoft.JET.OLEDB.4.0;data source = " + m_path + "data.mdb";
I skip the rest of code doing connection, reader, and query.
I am sure when I have my m_path change to a local path for a local mdb copy, it works. And I can download the mdb file when using the url path, so the url path is specified correctly. Anyone know how what I am missing?
Thanks

You can't connect to an access database via HTTP. You'll need to access it via a file share UNC (\server\share\access.mdb).

i think you have to some FTP upload n download temporary for that....
see this link
http://www.codeproject.com/KB/IP/SimpleFTPDemo.aspx
and when you put it in temp directory you got then local path.. of MS Access
OR
Open your "Client Panel" of website and make ODBC Driver/MS Access Database in that...
see the information about how to connect Database MS Access in your SitePanel.
you can see there all the informations like
How to...
Mail Client Settings, MS Access Database Connection, MS SQL Database Connection,
just for example in my domain panel i have this on ZNetPanel...
And then i think you knw how to connect ODBC !!

Related

How to connect to a SQL Server instance without knowing the Initial Catalog?

I'm writing a portable program that can be used on other computers as well as mine and It also connects to the SQL Database on that computer.
So the problem is that I don't have the database name of that computer. How can my program connect to that Database without previously knowing the database name?
In other words, I don't have enough information to create a complete ConnectionString.
Connect to SQL Server's master database first.
Then, using this query, you can get data from databases in your database:
SELECT name FROM master.dbo.sysdatabases
Using the site below, you can find the right Connection strings for you :
https://www.connectionstrings.com/
You can use a dot in the connection string to represent.tbe local server.
Create a txt file, rename the extension to UDL. Open the UDL file and put a dot, a full stop:
If you have installed a SQL Instance (ie not the default instance) it will be .\InstanceName
Choose the Database drop down and click Test Connect.
Finally close the URL file and open it with NotePad and you will see the connection string.

Connecting application to database on a pc over an intranet

I'm developing an application that needs to access files on computers in an intranet, the files are database files and each computer has its own database, from what i have read i need to use a //server connection string, however I want to code my application in such a way that the user selects the computer they want to retrieve the that from for example they would select "Computer 2" and the application would create the connection string, connect to the database and populate it
I would recommend creating a connection string for each machine you are accessing in the web.config file and then using the user's selection to pull the correct connection string from the config file to instantiate the connection.
I have it working with this code
string myconnectionstring = #"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\" + PCName + #"\data\data.mdb"

Connect to remote Access 2003 database which has linked tables

I've got this scenario: I developed a C# application which connect to a mdb file (Access 2003) through OleDBConnection (engine = Microsoft.Jet.OLEDB.4.0). This mdb file has some linked tables in another mdb file in the same directory. Everything works perfectly in the local environment, the query retrieves data from linked table even if I connect only the main mdb file. A simplified schema could be:
my application in the local machine --> C:\mydir\main.mdb --> C:\mydir\linked_tables.mdb
But this application should work in some host computers of a local network. And the mdb files are stored in a server in a shared directory. Well, when the application is running in a host I set the path as follow:
\\myserver\mydir\main.mdb
The connection works. The problem happens when I launch a query which tries to get data from linked tables. It tries to find the linked table in C:\mydir\linked_tables.mdb, but this path is on the server, not in the host.
Is there a way to tell him: if the path of the main mdb file is \\myserver\mydir\main.mdb you must (automatically) get the linked tables on \\myserver\mydir\linked_tables.mdb?
Thank you
I solved with another connection. I mean: for each mdb file I use a different OleDBConnection.
OleDbConnection MainConn = new OleDbConnection("\\myserver\mydir\main.mdb");
OleDbConnection LinkedTablesConn = new OleDbConnection("\\myserver\mydir\linked_tables.mdb");
Not so elegant, but it works. If I have to do some join of tables located in different databases, I manage them with some generic collection objects.

Having trouble connecting C# executable to database file on remote computer

Using VC# I've created a staff management app that, upon its first run, is expected to query the user for the path to a (.mdf) database which will reside on a remote computer. A resulting path may be something like
string dbPath = #"P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf";
Then I'm placing this string into a connection string template as so:
string dbConnectTemplate = #"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;Connect Timeout=30;User Instance=True";
string dbConnectionString = String.Format(dbConnectionTemplate,dbPath);
Then I'm attempting to connect to the database LINQ to SQL style
ManagementDBDataContext db = new ManagementDBDataContext(
dbConnectionString);
At this point, an error pop's up stating that
The file "P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf" is on a network path that is not supported for database files.
An attempt to attach an auto-named database for file P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
As I am relatively new to databases, I completely do not understand this message. And obviously, the file is not on a UNC share.
Any ideas?
Jim Lamb recommended that I connect to an instance of SQL server running remotely. Considering that I'm using LINQ to SQL, what refactoring do I have to do to make this happen? Other ideas still welcome - especially "push this button and everything will work" solutions.
Another clue: A coworker said that there used to be some way to work through Control Panel->Administrative Tools->Data Sources(ODBC) so that a remote database could be viewed from my computer as if it was local. The coworker didn't know any more details besides this.
You are attempting to connect to a database file on another machine over a network connection, which isn't supported by SQL Express. You'll need to make a local copy and attach to that, or connect to an instance of SQL that's running on the same machine as the MDF file.

connect Access via c#

i need to open a connection to a remote access db.
in the local environment to the remote acess db is working great .
when i run this application from production server (other server) it's fail with message
"
It is already opened exclusively by another user, or you need permission to view its data.
"
my code :
conString =
#"Provider=Microsoft.JET.OLEDB.4.0;"
+ #"data source=" \\150.248.248.38\d$\TestApp\vending.mdb;Jet OLEDB:Database Password=1234;";
OleDbConnection connAccess = new OleDbConnection(conString);
try
{
connAccess.Open();
objDiningRoom.Connection = connAccess;
....
}
catch (Exception ex)
{
}
finally
{
connAccess.Close();
connAccess.Dispose();
}
*Its not open in other place
thanks
This looks like it is a permissions problem.
Make sure you give the IUSR account (or whatever account ASP.NET runs as) read/write permissions to your database.
you can try :here
copied from there :
This commonly occurs when your database file is opened exclusively
by another application (usually MS
Access). Close all applications that
use this database and try again.
This error may occur if the account being used by Internet Information
Server (IIS), (usually IUSR), does
not have the correct Windows NT
permissions for a file-based database
or for the folder containing the
file.
Check the permissions on the file and the folder. Make sure that you
have the ability to create and/or
destroy any temporary files.
Temporary files are usually created
in the same folder as the database,
but the file may also be created in
other folders such as /Winnt. If
you use a network path to the
database (UNC or mapped drive),
check the permissions on the share,
the file, and the folder.
Check to make sure that the file and the data source name (DSN) are
not marked as Exclusive.
Simplify. Use a System DSN that uses a local drive letter. Move the
database to the local drive if
necessary to test.
The "other user" might be Visual InterDev. Close any Visual InterDev
projects that contain a data
connection to the database.
This error may also occur when accessing a local Microsoft Access
database linked to a table where the
table is in an Access database on a
network server. In this situation,
please refer to the following article
in the Microsoft Knowledge Base for a
workaround: Q189408 PRB: ASP Fails to
Access Network Files Under IIS 4.0

Categories