Access mdb file content from .net when mdb file has password - c#

I am creating a window application in C# and was thinking of setting up a password on mdb file of MS-Access so that no one can open that file other than my window application or who so ever knows password of that file.
I managed to make that file password protected but unfortunately I was not able to access that file through my application. Actually i not getting where to set the user name and password to open that file. Entering username and password in connection string is not working.
EDIT
Sorry for bit confusion
I want that file to be password protected rather than database connection.
That file should not be opened in any case. For that i managed to set password on file using ms access itself but i m not able to open that file through my application.
Edit2: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb; User Id=""; Password="abc";"
I am using MS-Access 03
Edit 3:
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\Projects\GargTubes\dbGargTubes.mdb;
Database Password=abc;"
Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\Projects\GargTubes\dbGargTubes.mdb;JET
OLEDB: Database Password=abc;
Error: Could not find installable ISAM

Try setting the database password in your connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;Jet OLEDB:Database Password=MyDbPassword;

You can take a look into that connection strings samples: Connection strings for Access

Since you are talking about passing user name and password, I assume that you have protected your database by setting user rights rather than by using the "database password" option. In that case, users and groups are stored in system.mdw. Be sure to include the path to system.mdw in your connection string (Jet OLEDB:System Database=path\to\system.mdw, see Connection strings for Access for samples).
Alternatively, you use the "database password" feature. Then, the Jet OLEDB:Database Password option described in the other answers should work. To spell it out:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Projects\GargTubes\dbGargTubes.mdb;Jet OLEDB:Database Password=abc

Related

C# building/resource/publish/create and exe file with database

I was wondering how can I create the exe file for the app I made. I tried giving the exe file in the bind/debug folder together with the database (MS Access). But having an error with the filename of the mdb file, it is pointing to my directory.
{
InitializeComponent();
connection.ConnectionString = #"Provider=Microsoft.Jet.OLEDB.4.0;
Data Data Source=C:\Users\asdf\Documents\questionbank.mdb;
Persist Security Info=True;
Jet OLEDB:Database Password=asdfasdf";
}
And the error getting is "Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item.
Put your connection string in a configuration file, eg., by createing a setting in the Settings tab when you right click on your project and go to Properties.
Hard coding your connection details, as you've done, means it cannot change when you deploy your application.

C# Connection string save into AppData?

So I have a DB (webster.accdb) which will be getting installed on a server (eg. \SERVER\WEBSTER)
However different locations may have differing SERVER names (ADMIN1 etc etc)
When the program originally installs, it checks the con string in app.config which I have put as "DEFAULT" - literally the string.
The program checks the connection string in app config, and if it is DEFAULT, then it runs a little prompt i have made which asks for details from the user regarding the server name and a few other specifics.
They click "connect" and it writes the newly constructed connection string to app.config and the program loads after a series of tests.
Now this works under VS tests and installs on D: drives in temp folders. My issue is that if 'properly' installed to the programfiles section, then we now have the issue of access being denied to alter the file.
So could someone point me in the right direction with regards to the correct process as i know I'm doing it wrong:
Create an XML in Appdata for the user, which has the con strings, and this is generated on first use, and is used for the constrings from then on?
Save the con strings as Settings, and use This code to update settings, then make sure all my con strings in my program no longer point to configuration, but to settings??
Something better because I am clueless and this is totally not how i should be doing this at all!
Code used to update the config:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["LOTSConnectionString"].ConnectionString = "Data Source=" + txtpcname.Text + ";Initial Catalog=" + cmbdispense.SelectedItem + ";Integrated Security=False;User ID=webbit;Password=ill923r6MG";
config.Save(ConfigurationSaveMode.Modified, true);
Access Denied means the user which is executing the app either does not have permission or because of inbuilt security by Operating System, app is executing under restricted permissions. Try executing app with Administrator by right clicking on it and choosing run as.
You can prevent this by Setting up connection string at the time of installation instead. Prompt a user to enter details during installation.
So pretty much I self confess to not understanding the benefits of the USER section of the config.
I have changed my connection strings to just "STRING" and put in the USER section of Settings.
Now i can refer to my strings as
properties.settings.default["ConString"].tostring
This is then saved to User/APPDATA/Local
For noobs like me reading this, that means the original app.config file in programfiles stays THE SAME, but an excerpt is taken out of it relating to the user section and put into appdata.
What was confusing me the whole time was selecting "connection string" in settings, which didnt allow selection as a USER setting.

Connect a C# MVC application to a remote SQL Server database

I have a SQL Server database located at http://192.168.10.3/MyDB. I have created a C# MVC application, and I need to know the steps to connect my application to the above database.
Is it only replacing the connection string in the web.config file ?
Data Source=?? ;Initial Catalog=??;Integrated Security=SSPI;
User ID=??;Password=pwd;
If so what am I to replace where I have placed the ?? sign ?
DataSource = 192.168.10.3
Initial Catalog = MyDB
User ID = whatever sql login you are using to access your SQL Server
Password = password for the sql login above
The other answers here are good. In addition, ConnectionStrings.com can be your friend, especially if you are going to connect to various types of databases in the future. Select the database that you need to connect to and then you'll see the different connection strings you can use for that database.
http://connectionstrings.com/sql-server-2012#sqlconnection
you can try this
create a new text document on your desktop - conn.txt
change file extension to udl (conn.udl)
double click to open the file in the first tab select appropriate provider
4 . in the second tab enter server name (ip address,port), username, password (check Allow saving password) and database name.
test connection
if the test reports success close the window.
open the file with notepad, copy everything but the provider name and paste it back to connectionString
Below is connection string you need for:
Data Source="192.168.10.3" ;Initial Catalog=MyDb;Integrated Security=SSPI;
User ID=sa (for example);Password=whatever you set before;

Get data from password protected Excel file using OleDB

I'm using this connection string to access excel(2007,2010) files
oleConnection.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties='Excel 12.0;HDR = NO;IMEX = 1;'";
this work fine until i try to get data from protected List.
I know the protection password.
So how could i access protected list?
As per MSDN you can provide the credentials with the connection string User ID=UserX;Password=UserXPassword but this works for access
But
I'm afraid. You cannot open a connection to a password-protected
spreadsheet unless you have already manually opened the spreadsheet in
Excel . The described error is with the
Excel ODBC provider, but the behavior is identical in the Jet 4.0 OLE
DB provider. Your other option is to remove the password from the
spreadsheet, and rely on some other security mechanism (like
restricting permissions on the folder where the file resides) to
control access.

how to connect to access 2007 with c#

hey,
i am new at connecting to dataBases and for some reason each time i use those following lines my program collapse:
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=|DataDirectory|\Company.accdb"
OleDbConnection con = new OleDbConnection(connectionString);
inside my debug folder i got Company.accdb access file
edit:
i am getting 'Microsoft.Ace.OLEDB12.0' provider is not registered on the local machine any idea how to solve it?
thanks in advance for your help
Two things -
This connection string rely on ACE OLEDB provider (typically comes with Office 2007 - your machine need to have this provider)
Connection string is requesting data dictionary. You probably need to use below form:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;
For password protected files, form would be Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;
I will also suggest trying different Provider (ODBC perhaps) instead. For various connection strings for Access 2007, refer http://www.connectionstrings.com/access-2007

Categories