Timothy Mothra

I'm workin on converting a C# program from VS2003 .NET 1.1 over to VS2005 .NET 2.0 . The program accesses an Access 97 database with a password.

In the original program, the following connection string works:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"C:\\SLData\\Database\\SLDebit.mdb\";Jet OLEDB: Database Password=\"PaSsWoRd\";"

The new program crashes at: connection.Open

I'm fairly certain that the problem is that the Database Password property isn't getting set. If I pause runtime and add a Watch on my OLEDBconnection object, I can't even find where this property exists to check if it was set.

In VS2005, I tried to add a new database through the Server Explorer and was able to verify that all of my above information is valid. Through the server explorer, I was able to view all the database columns and rows. When using the Connect to a Database wizard, I paused to view it's Advanced. settings before clicking Ok. This view of the properties resembles that of a Watch and I could see that the Database Password property indeed had to be set inorder to connect.

I'm stumped. This all has to be accomplished programically. If anyone can offer any help, it would be greatly appreciated.



Re: .NET Framework Data Access and Storage Help connection to a database.


Re: .NET Framework Data Access and Storage Help connection to a database.

Timothy Mothra

oh boy, somebody can use google search.

NO Adamus. I know how to use connection strings. I need to know how to correctly pass the database password to the OLEDBconnection object.





Re: .NET Framework Data Access and Storage Help connection to a database.

Adamus Turner

Timothy Mothra wrote:

oh boy, somebody can use google search.

NO Adamus. I know how to use connection strings. I need to know how to correctly pass the database password to the OLEDBconnection object.

lol it's in the connection string.

Good luck,

Adamus






Re: .NET Framework Data Access and Storage Help connection to a database.

Timothy Mothra

The authentication takes place when i execute connection.Open()

An exception is thrown that says that I don't have the permissions to open the database. It's an XP machine, so i set the folder's permissions and the database file's permissions to include Everybody just for now.

I have to set "Jet OLEDBBig Smileatabase Password" equal to my password. But I don't know how check that it was set before trying to execute Open .

When I set a breakpoint, and view the properties of my oledbconnection object, "Database Password" isn't listed. This is because from what I can tell, it's not actually a property of oledbconnection object, but of the provider Microsoft.Jet.OLEDB.4.0.

Let me repeat, that I havn't changed any code. The code that I originally posted above works in the .NET 1.1 environment. The .NET 2.0 environment throws an exception at connection.Open()

Let me also repeat that the database exists and works. I can open it through Access, and I can open it through the VS2005 Database Connection wizard, and view that connections properties and see where a "Database Password" property exists and the password was stored. But it's not working for me programically.





Re: .NET Framework Data Access and Storage Help connection to a database.

Adamus Turner

Let me also repeat. The connection string is wrong.

Fix your connection string and the problem is solved.

Adamus






Re: .NET Framework Data Access and Storage Help connection to a database.

Optimus Crime

As helpful that might seem. I was assume the orginal poster would like help fixing the connection because i also assume that since he is posting he has tried to fix the string since he stated just that

And saying something as broad as fix your connection string does not prove you know anything. If you would try to make suggestions on what to changed or ask for some information if needed






Re: .NET Framework Data Access and Storage Help connection to a database.

Timothy Mothra

Care to share what you see that is wrong with the connection string or why the same connection string works in .NET 1.1



Re: .NET Framework Data Access and Storage Help connection to a database.

Adamus Turner

It works fine for me when you use the correct connection string and syntax.

Here you go. I'll post all of the code. Replicate the exact syntax of the connection string and it will work fine.

Imports System.Data

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim sqlConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\adturner\Desktop\PacMan.mdb;Jet OLEDB:" & "Database Password=password")

Dim sqlDataReader As OleDb.OleDbDataReader

Dim myQuery As String = "SELECT * FROM AdamUsers"

Dim sqlCmd As New OleDb.OleDbCommand(myQuery, sqlConn)

sqlConn.Open()

sqlDataReader = sqlCmd.ExecuteReader()

While sqlDataReader.Read

MsgBox(sqlDataReader.Item(1))

End While

sqlConn.Close()

sqlConn = Nothing

GC.Collect()

End Sub

End Class

Hopefully you can transpose this into C#. If not, reply and I'll convert it.

Adamus






Re: .NET Framework Data Access and Storage Help connection to a database.

Adamus Turner

Timothy Mothra wrote:
Care to share what you see that is wrong with the connection string or why the same connection string works in .NET 1.1
Gladly. The reason the connection string is wrong is because it's not correct. You should read links that people post instead of being cynical.

Adamus






Re: .NET Framework Data Access and Storage Help connection to a database.

jgalley

wow.

How hard would it have been to actually help the OP

While I am not sure I have the answer I will offer this:

First, in general your Access DB need to be read/write to the IUsr_machinename account. Opening the database will create an .lck (lock) file. That file also needs to be read write so you will want to set the permissions on the directory with the .mdb to read/write/create with cascade.

Second, I think you don't need (or want) the extra internal quotes or escapes in the conncet string.

Try:

"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\SLData\Database\SLDebit.mdb"; Password=PaSsWoRd;"




Re: .NET Framework Data Access and Storage Help connection to a database.

Timothy Mothra

Ok.. it is woring now...

perhaps i was just too stressed out last night from having worked on this single problem for 6 hours.

This is the code that finally works:

OleDbConnection connection = new OleDbConnection(

@"Provider=Microsoft.Jet.OLEDB.4.0;"

+ @"Data Source=C:\SLData\Database\SLDebit.mdb;"

+ @"Jet OLEDB: Database Password=PaSsWoRd;");

OleDbCommand command = new OleDbCommand(sqlStatement, connection);

try

{

connection.Open();

command.ExecuteNonQuery();

applicationDA = new OleDbDataAdapter(command);

dbDataSet = new DataSet();

applicationDA.Fill(dbDataSet, "AppData");

dbDataTable = dbDataSet.Tables["AppData"];

}

Thankyou everybody for their input. I swear I had tried this once before, but apparently not. I was brought into this project because other people were less elegant with their coding and nothing at all was working and they were dragging everybody else down with them.
Just for your own curiosity, this is the original connection string I had to work with:

this.oleDbConnection1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Jet OLEDB: Database Password="""+App["DebitPass"]+@""";Data Source=" + App["DbDirectory"] + @"\SLDebit.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB: System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB: Database Password="""+App["DebitPass"]+@""";Jet OLEDB:Engine Type=5;Jet OLEDB: Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB: Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB: SFP=False";

But stuff works now when hardcoded, so things should work when the connection string assembles itself.

Thanks again.






Re: .NET Framework Data Access and Storage Help connection to a database.

Timothy Mothra

Sorry, I wasn't trying to be cynical. When I posted that message, your previous reply wasn't present. These time stamps are all wrong.