Problem: Adding a column to MS Access DB that is used by a VB.NET program via OLE no longer updates the automatically generaate code - vb.net

I have a VB.NET program that I wrote 20 years ago and last updated 7 years ago. I have gotten a new computer and new version of Visual Studio recently.
The program uses a DB created with MS Access via the OLEDB mechanism. I originally created the DB connection by dragging and dropping tables from the DB into a VB window. This generates a lot of code automagically that I have never had to look at in the past. This code takes care of the DB queries and updates. Code I have explicitly written adds, modifies or deletes rows from the tables.
In the past I have been able to manually add a column to the Access DB and get the automatically generated code to update and make that column available to my code.
I am trying to do that now and I've either forgotten a crucial step or the newest version of Visual Studio is not compatible with my ancient code. The symptom is the new column does not get updated when I update all the other columns. If I look at the automagically generated code (in routine InitilizeComponent) it has lines like:
Me.OleDbUpdateCommand5.CommandText = resources.GetString("OleDbUpdateCommand5.CommandText")
Me.OleDbUpdateCommand5.Connection = Me.dcWageLossDB
Me.OleDbUpdateCommand5.Parameters.AddRange(New System.Data.OleDb.OleDbParameter() {New System.Data.OleDb.OleDbParameter("CaseId", System...
where in the arguments of the last call it lists all the columns EXCEPT for my my new one.
Note that while the new column does not get properly added to the DB queries, it does get added to internal structures so that in my code I can refer to the new column by name and set its value.
I know this question is rather fuzzy. It is not practical to provide the (quite long and complex) code. Since the problem probably depends on the long history, it also is not practical to try to create a small simple version of it.
I'm just hoping someone has run into this problem and knows the solution.
Thanks
I have already tried graphically deleting and adding back all the tables in the .xsd file used in the query via the solution explorer - data connections. It didn't help.
In desperation, I also tried modifying my hand the automagically generated code, adding it the new column in a fashion similar to what it had for all the old columns. I couldn't make that work.

Related

MS Access Macro/VBA Non-Sense

I have a fairly complex database that has worked for quite a while. Today I went to troubleshoot something and I got a non-sensical error.
In my macro, first I create detail tables. Then I number each row sequentially in the detail table with a VBA script. Then I create a summarized version of that table including the just the key info like SKU and row number. (The rest of the details are added back later using the row number). The numbering script is working. The detail tables have the row numbers. However the summary table does not have the row numbers after running the macro. If I manually click the queries to add the summary tables, the numbers magically appear.
Please help. This database has worked for over a year without this problem.
Honestly it sounds like its corrupt. MS Access uses the Jet Engine which is known for bloating dB size and quite easily becoming corrupt.
You can see by the odd behaviour, the program is having trouble with the underlying file. If you open a new Access DB it won't exhibit the same problems.
The best bet is to recreate the dB from scratch or port it to SQL Server, PostGres, MySQL, SqlLite etc and put the application logic in a program - even if its a VB6 app, though I'd recommend .Net.
I've got the code to strip out every thing and recreate the MS Access dB here:
https://stackoverflow.com/a/16158027/495455

Creating a working copy of an old Access 2010 database

I am tasked with fixing some bugs that an access 2010 database, written 10 or so years ago, has. The database has been functioning but has a few bugs in report generation that need to be fixed (ie: bugs are not impeding overall functionality).
Since I am relatively new to access 2010, I wanted to create a working copy of the entire database, VBA and all, so that I could get into the VBA code and figure out what is causing the bugs without accidentally sending some of the automatic emails or changing pertinent information in the data. I have tried saving the database with a new name, copying it in the folder and pasting elsewhere, and creating a backup and saving that elsewhere.
Each attempt yields the same issue: the VBA project not being readable. It gives the following message when I open any copy:
if included picture doesn't load: tl/dr: database cant be opened because VBA project cant be read, if "ok" is clicked vba project will be deleted..I have searched high and low, asked everyone that has used the database, nobody knows how to fix the issue and I do not feel comfortable changing anything in the live copy.
Any assistance would be greatly appreciated. Thank you in advance.
One option you might try is to create a new blank database file and attempt to import all of the database objects from a copy of your target database into the new database file using the import wizard. If that's successful it won't be an exact replica of the previous database with regards to settings, but will include all of the database objects/code at least.

Fixing a broken database .NET

Okay so I am working in Web Forms but the problem would also apply to MVC I am assuming since both have the option of creating a users database on project creation. I deleted a data table on accident and updated the database instead of deleting the database itself because I was trying to recreate it with the seed data. I didn't realize that deleting a data table would do something different from deleting the database itself. The only backup I have is pretty old, so I would prefer to use a different way to fix things if that exists. How would I fix things?
I have it working now. What I did to fix it was I went to my back up although it could have just been a brand new project, both would have been fine, and I copied the SQL script for the data table that I deleted. Then I went to my broken program and created a new data table in the spot where it was before and replaced the code with the code from the back up. I saved it and hit update and it updated the database for me.

Access is not showing the records I have entered through vb.net form

I am new in vb.net programming. Am facing a problem in database handling. Am using oledb to deal with database, which is MS Access in my project. I am dealing with queries at the time. Now the problem is that my queries are working well on vb form but are not affecting the actual database. For example, when am adding a record, it displays 'record added successfully', the message I have used for my conformation, but the actual database is not displaying the record I just entered and even got the above conformation message as well. I have checked query in sql editor too, its doing well. I have checked locals in vb debug mode, all are containing correct values.
Am not getting what's the reason behind that. Why it is displaying the success message but not modifying the actual database. Same is the case when am firing delete query, till now. I have not tried Update query yet.
Technology - Visual Basic.net with MS Access
Am using Access 2007 and Visual Studio 2013
Please Help by your suggestions
Do the controls on your form have the correct control source, i.e. the database table/query from and to which it should be reading and writing to?
Basically the problem was the gap between my understanding and .Net's working.
Here is the solution.
You can include database in two ways:
1.Either importing it directly to your project from the place, for example using drag and drop, or some other such method.
2.Or, by including it via using wizard.
But, the difference lies in connection string you use in your project, if you give absolute path of database, then you will directly see the alterations in database you have done using your application, even in testing and debugging mode via IDE.
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\xyz.accdb"
But if you are using connection string provide by wizard, for example,
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\xyz.accdb"
what the IDE will be doing is whenever you will be running project for debugging or testing, every time, it will copy the actual database, with its contents as well, in /bin/Debug folder. So, the changes you are performing will only be visible to that copy, not the actual file. So, if you want to verify with the database, like in our case, check the copy of database, which will be present in /bin/Debug folder. You will see the changes there. But, every time you run project for debugging, it will replace that copy with original one.
So, actually I was checking the original database file, not that copy, since the changes were only made to that copy. So that is why I was facing the above problem, not due to any programming fault.

SQL in Visual Studio 2010 & LINQ

I'm working on a project which relies on the presence of a number of tables, views and stored procedures. Until now I have built these all in SQL Server Management Studio.
Now I would like to continue to work on them inside of Visual Studio. This will provide the benefit of version control (along with a number of other benefits hopefully).
I have added a new project to my solution and started working on one of the views. When I tried to build the solution it failed as the new project didn't have a server/database associated: Error 1 SQL03006: View: [dbo].[vw_Test2] has an unresolved reference to object [EV870_ACCT_MASTER].
I was able to overcome this by
-creating a dbschema dump using vsdbcmd.exe
-adding the dbschema dump as a reference to my database project
Is this the correct approach?
Now i can see the schema (tables, views, sprocs etc) in the Schema view (I had to enable display of "external elements") and the error message has gone away. Note: I had to reference like: [$(SQLDatabase)].[dbo].[EV870_ACCT_MASTER]
Now I want to know how I can work with these objects that i've scripted. I don't know how to use the new tables, views, sprocs etc (I want to use LINQ). Do i have to run the scripts first? How then if they are "CREATE OBJECT" scripts, will they run in future (presumably they'd fail as the object already exists in the database). Will my project/solution know which objects need updating and update them?
Ultimately want to take it a lot further- my aim is that the solution will be portable and a the server/database will be configurables. Then my tables, views and stored procedures will be created or amended if they don't exist or are out of date. Is this possible?
When I then start working with the views etc using LINQ I want those server/database references to remain dynamic?
I know there are quite a few questions in there but i'm hoping someone will be able to point me in the right direction- there doesn't seem to be much useful documentation online (or that i've stumbled across so far).
Thanks
Lee
Where I work (and the last place I worked) we distribute the sql scripts to create the database along with the app. In sql a version number is stored and when the app is run it checks to see if its version is newer than the number stored in the database. If so then it knows it may need to run some new sql scripts in case there were any schema changes. When this happens, we just run through all the scripts because they are written in a way that running them multiple times won't hurt anything... this way we don't have to worry about tracking which scripts are the new ones. Just check the version number and that's it.
As far as working with this stuff in Visual Studio instead of Management studio, I'm not sure why anyone would want to do that. Depending on what you use for source control you may be able to get hooks for Management Studio, but even if not that doesn't stop you from keeping your sql scripts in source control. And I wouldn't switch from working with my sql files in management studio to visual studio for the benefit of having built in source control any day.