OK, so I'm finally transitioning from VB6 to VS 2005 and it is excruciating. I do a lot of db programming in VB6 and Access 2003 and just trying to connect to a table in VS2005 has taken me several hours. I finally could read data from a table and populate a listbox and then it suddenly stopped working and I get a very cryptic error message.

"Request for the permission of type 'System.Data.OleDb.OleDbPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

This is a work-group database, so I have a system database file I must access in the connection string. It was working and then for some reason the data connection dropped all of the username, password, and system db information. It was still in the connection string, but no longer in the data source properties window.

I tried several things and finally deleted the the data connection and recreated it. I click on "Test Connection" and the connection succeeds. I can see the tables and even use the Query Builder and see the data. When I try to access with code and populate a listbox it fails with the error message above. Its very frustrating.

It is on the "da.Fill(ds, "tblCondition")" line that it bombs. It was working!!!

' Creating connection and command sting
Dim conStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='X:\NetProjects\PecsysInload\PecsysAll.mdb';Persist Security Info=True;Password=paswrd;User ID=usrnme;Jet OLEDB:System database='X:\NetProjects\PecsysInload\fmc2003.mdw';Jet OLEDB:Database Password=M2ctsdmrt"
Dim sqlStr As String = "SELECT * FROM tblCondition"
' Create connection object
Dim conn As OleDbConnection = New OleDbConnection(conStr)
' Create data adapter object
Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlStr, conn)
' Create a dataset object and fill with data using data adapter's Fill method
Dim ds As DataSet = New DataSet
da.Fill(ds, "tblCondition")
' Attach dataset's DefaultView to the datagrid control
Dim dv As DataView = ds.Tables("tblCondition").DefaultView
lstCondtions.DataSource = dv
lstCondtions.DisplayMember = "ItemName"

Any help is appreciated. Also, any good books that would ease the transition would be helpful.

Thanks

i reccomend "Visual Basic 2005 Step By Step" my microsoft press, you can get it off amazon and it has lots of code samples and expalins changes between VB6 and .NET, has a section on basic ADO.NET using VB and MS access too

Something very odd is going on. I recreated the application and it worked. It was late and I shut it down. Today when I reopened it I received the same error. It is not the code. For some reason, a setting or something is not being saved and I don't know what it is. Both the MDB file and the MDW file have LDB files, so the program is finding the database and opening them. Just as before, the connection tests OK. I can see the tables and data with the query builder, but the stupid POS code will not access the data. My God this is frustrating!

THE CODE DIDN'T CHANGE!

I feel like I'm trapped in a cave and making notes on slivers of paper about my ordeals. I got my code to run again with out changing one letter or declaration.

Here's what I did:

I deleted all data sources from the project. EVERYTHING from the Solution Explorer and from the Data Source window.

This caused a new error so I went to the the "Solutions" \bin\Debug folder and deleted everything from there. Wiped it all out.

I then went to the Projects\Properties\Security tab and checked Enabled ClickOnce Security Settings and selected "This is a full trust application".

What do you know it worked. I still can't figure out why the hell it worked at first and then stopped. I DIDN"T CHANGE ANYTHING!

Oh, and I should add that before I deleted the data sources, I tried the "Enabled ClickOnce Security Settings and selected "This is a full trust application"." and that didn't work.

It was only after I removed all of the data sources and wiped out the bin\debug folder that that worked.

Does anybody have a clue as to what the hell is going on?

I finally figured it out. VS2005 did not like running my projects from the NAS I have attached to my router. I store everything on the NAS so I can access my files from different computers. This seems to have been seen as some sort of security issue. Even though I fooled with the security settings, I couldn't get it to work. I moved all of the source files to my local C: drive and the problems went away.

Lesson learned the hard way.

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.