Any Option to Save Changes to Database?

  • Thread starter Thread starter Jonathan Wood
  • Start date Start date
J

Jonathan Wood

Okay, I finally got databases working with my ASP.NET projects. Now, I'm
back to WinForms so here we go again.

I understand that when creating a database file in my project, the default
settings is to silently wipe out any existing data each time I run my
project. (Brilliant!) So I'm creating a test project in VS 2005 that uses a
SQL Server Express database. I then created a Windows form and bound my edit
controls to a table in the database. I'm able to add any number of records
and browse through them. But, again, if I terminate and restart the project,
all the data is gone.

SQL Server databases don't have a "Copy to Output" option so I'm not sure
where to go on this. I guess Microsoft just assumed anyone working with
WinForms wouldn't want to keep any data they created.

Does anyone know the trick to making my database changes permanent?

Thanks.
 
Jonathan,

I'm pretty sure that SQL Server Express databases have the "Copy to Ouput"
option.

Kerry Moorman
 
Kerry is right. When you incorporate the SQL Server database (file) into
your project, it too is subject to the infamous "Copy to Output" setting.
I'm not a fan of this approach and frankly, I don't expect it to last much
longer. I you insist on this approach (and there are several that are far
better supported and more widely adopted described in my book), you need to
set the file property to "Copy if Newer" or "Don't Copy".

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
If I select the database under Data Connections in the Server Explorer,
there's only a couple of properties and none of them are "Copy to Output."
And they're all greyed out anyway. As I think I mentioned, I'm not attaching
a database file. It's a SQL Server Express database. So where would I got to
find this option?

Thanks.
 
The option may make sense in some cases. But to wipe out your data until you
can figure it out just seems stupid to me. It initially cost me a support
call, and now I seem to be dealing with it all over again.

If I select the database under Data Connections in the Server Explorer,
there's only a couple of properties and none of them are "Copy to Output."
And they're all greyed out anyway. As I think I mentioned, I'm not attaching
a database file. It's a SQL Server Express database. So where would I got to
find this option?

Thanks.
 
Again, there is no "db file" in my solution explorer. I am not using an
attached file. The database was created as a SQL Server database. I've
described this several times now and am not sure if I'm using the exact,
correct terminology. But I can tell you there is no database file listed
under solution explorer.
 
Jonathan,

While debugging your vb application, use Explorer to look in the app's
bin/debug folder for the database file. If it is in the bin/debug folder then
it is in fact being copied to the output folder for debugging purposes.

If you don't see the database file being copied, then while your app is
running, make some change to the database. Then while your app is still
running, use SQL Server's Management Studio to see if you can see the changes
to the database made by your app.

These techniques might give you a better idea as to what is going on.

Kerry Moorman
 
Kerry,
While debugging your vb application, use Explorer to look in the app's
bin/debug folder for the database file. If it is in the bin/debug folder
then
it is in fact being copied to the output folder for debugging purposes.

Well, it's not a VB app but, okay, I used *Windows* Explorer to look in the
apps bin\debug folder while the application is running and after I have
created some data. This directory contains the following files:

TestApp.exe
TestApp.exe.config
TestApp.pdb
TestApp.vshost.exe
Testapp.vshost.exe.config

So I don't see any database file. I really didn't think there would be one,
it's stored in the SQL Server database store somewhere. But, either way, my
data is not persisting.
If you don't see the database file being copied, then while your app is
running, make some change to the database. Then while your app is still
running, use SQL Server's Management Studio to see if you can see the
changes
to the database made by your app.

These techniques might give you a better idea as to what is going on.

Well, I did create some data as mentioned previously. I don't have SQL
Server Management Studio available but I tried using Visual Studios Server
Explorer. It seems to show no data has been created.

It had occurred to me if, in it's infinite wisdom, Microsoft not only
decided to overwrite my database file every time I ran the program, but
perhaps it has a way to prevent my data from being saved in the first place
when it's a SQL Server database. Either way, the fact that I seem to get
screwed either way and, when talking to people in the ADO.NET forums on both
occasions, neither seemed to be a known issue, just makes me feel like
throwing my computer out the window at the moment.

Thanks.
 
Jonathan,

Maybe you could post some of the code that you are using to persist the data
to the database.

Kerry Moorman
 
There is no code. Again, I'm databinding form controls to a table. And I'm
using the navigation control to add records.
 
Jonathan,

I'm not all that familiar with the navigation control, etc. But surely at
some point you need to initiate some process for persisting local data back
to the database?

Somewhere there needs to be a call to a tableadapter or dataadapter's Update
method, right?

Again, I do all that stuff manually, but its hard to believe that even with
databinding, navigation controls, etc. you don't need to do something to
persist the data.

Kerry Moorman
 
Kerry,
I'm not all that familiar with the navigation control, etc. But surely at
some point you need to initiate some process for persisting local data
back
to the database?

Well, that makes two of us who are unfamiliar with the navigation control.
As I mentioned previously, I did get database stuff working in ASP.NET
primarily via stored procedures. This here is new to me.

I don't assume either way about needing an additional step to persist the
data. If one is needed, and I knew what it was, I'd be up and running.
Somewhere there needs to be a call to a tableadapter or dataadapter's
Update
method, right?

I assume the control makes many calls that I don't know about. I don't know
a lot about ADO.NET but, yes, if the data is only being stored in a dataset,
then it somehow needs to update the database.
Again, I do all that stuff manually, but its hard to believe that even
with
databinding, navigation controls, etc. you don't need to do something to
persist the data.

For me, it's hard to believe that this stuff is so counter intuitive. While
I'm primarily a C++ programmer, I spent many years with classic VB. Back
then, you could learn this stuff in no time. Apparently, MS is using a
different criteria to determine how their development products should work
these days.

Thanks. Maybe someone else has dealt with this before.
 
If this is part of the connection string then, no, I'm not. BTW, my
connection string is the one generated automatically.

Thanks.

Jonathan
 
That's no guarantee that you aren't using the suspect User Instance=True
option. I would inspect the generated ConnectionString to be sure. Yes, the
..MDB file will be in the Project menu if you choose to add it to the project
during the Data Sources setup wizard.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
okay... In this case, your connection must be being made against a static
(shared) instance of SQL Server. Frankly, this is unusual as the typical
drag-and-drop paradigm incorporates the .MDB file into the project and it
behaves as you describe. The User Instance feature (again, the typical
behavior) creates a user-specific instance of the SQL Server Express DB
Engine upon first invocation.
I suggest using the SQL Profiler to monitor the instance (if you can find
it) and see what's getting executed. This will show the underlying
operations in some detail. Note that the User Instance is generally not
visible.
--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
 
I think the database is okay.

I played with the data sources window and ended up dragging a table to a new
form. When I do, the navigation bar created includes a save button where
mine did not. For whatever reason, I guess Microsoft just assumed people
adding the navigation control manually wouldn't want to save their
databases.

Right now, I'm pretty sick of this. Every one of the few times I've played
with databinding and WinForms, I haven't liked it, and for a list of
reasons. (I still love ASP.NET!) As was suggested earlier, an additional
step was required to write the data back to the database. I probably won't
play with this again for a while.

Thanks to everyone who offered advice!
 
Jonathan,

Why are you blaming Microsoft developers so often in this message thread,
while probably almost a million developpers can work with what they made,
but you not?

Just tell about your problem there are a lot of people who can help you as
you describe that well.
The way a problem is described makes how good the solution can be.

Cor
 
Cor,
Why are you blaming Microsoft developers so often in this message thread,
while probably almost a million developpers can work with what they made,
but you not?

Because I feel they've made some poor decisions. That people have been able
to figure out unintuitive decisions does not make such decisions intuitive.
And, based on my discussions (this thread is a perfect example), I'm not the
only one finding these decisions unintuitive.
Just tell about your problem there are a lot of people who can help you as
you describe that well.

Your assessment is that I have not described the problem? Then I can only
assume you have not read my posts.

Jonathan
 
Back
Top