Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello

This is what I have. I have a query that works without a password.
C#
OleDbConnection objConnection = null;
OleDbCommand objCmd = null;
String strConnection
strConnection = (@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\AccessDB1.mdb");
objConnection = new OleDbConnection(strConnection);
objConnection.ConnectionString = strConnection;
objConnection.Open();

strInsertSQL = ("Insert into Main(" +
                "ID, " +
                "ItemNum, " +
                "DataType, " +
                "Data, " +
                "Tesxt) ") +
                "SELECT " +
                "ID, " +
                "ItemNum, " +
                "DataType, " +
                "Data, " +
                "Tesxt " +
                " FROM [MS Access; database=c:\\AccessDB2.mdb;].[tblMain]" +
                " where Tesxt in (1,2,3,4)" +
                " order by ID";
            objCmd = new OleDbCommand(strInsertSQL, objConnection);
            
            objCmd.ExecuteNonQuery();
            objConnection.Close();


Now I'm trying to connect to AccessDB2 when its password protected. The password is qwerty123.
I've tried this
C#
" FROM [MS Access; database=c:\\AccessDB2.mdb;Password=qwerty123].[tblMain]" +

This didn't work. Visual Studio 2010 errored out and said "Not a Valid Password" How is this possible?? It is the password that I put in to Access when I open AccessDB2.

I've tried this
C#
" FROM [MS Access; database=c:\\AccessDB2.mdb;Jet OLEDB:Database Password=qwerty123].[tblMain]" +

This didn't work either.

I've tried this
C#
" FROM [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\AccessDB2.mdb;Jet OLEDB:Database Password=qwerty123].[tblMain]" +

This didn't work either

I've tried every variation on this. Why is it that I can connect to AccessDB2 without a password and then when I try to use a password I'm not able to do the insert. Does anyone know why or have a solution??

Here's another question. Is there another way to do the exact same thing another way??

Thanks
Posted

1 solution

Why not read all the data in to memory, then insert it from there ?

Tesxt

Is this really a column name ?
 
Share this answer
 
Comments
mzrax 18-Jul-12 22:27pm    
Yes Tesxt is the actual column name. It was a mistype from the original programmer.

How do you put everything in memory and then insert it into another DB? I've been able to put it in memory from one DB but I've never been able to get it into another DB.
Christian Graus 18-Jul-12 22:40pm    
Gotta love quality control....

You read it, put it in an array, then iterate over that array to do the insert.
mzrax 18-Jul-12 23:01pm    
I've been able to get the table into a dataset from one DB but how do I get it from that dataset and insert it into anther DB or am I off the mark?? What would it look like??
Christian Graus 18-Jul-12 23:06pm    
You can iterate over the data set to read values to insert, or you can read them in to an interim class. You'd iterate over the data each way, and create an insert for each line of data and run it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900