Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem saving from VB 2005 app to SQL Server Express 1

Status
Not open for further replies.

Sprowler

IS-IT--Management
Sep 30, 2002
102
0
0
GB
Hello everyone,

Hope someone can help with my problem.

I am writing a VB 2005 Windows Application connecting to a SQL Server 2005 Express db. I can connect fine and read data out, but cannot save anything to the database.

I use a SQLDataReader to retrieve data from the db, and use the SQLCommand.ExecuteReader statement to invoke a SP which carries out an UPDATE to one table, and an INSERT to another (from within the same sp).

When an item in a listview is selected, a DataReader retrieves the details from SQL Server based on the a "companyID", i.e. I only get back records for a customer selected from the listview.

When I refresh my form, the changes are displayed in the listview and other controls, and even if I close the form and reopen it they display.

Here is my problem... When I quit the app and restart it, my changes are not there. I have used Server Namegement Studio Express to see if the data has changed and it has not.

I cannot understand why, so will be very grateful for your help as this is an app for a customer. At this stage I can't post code because there are 32 parameters in the stored procedure, so the cope snippet will be quite long.

A link to some code samples would be helpful too.

Thank You in advance.
 
Select the database file (.mdf) from the project explorer. Make sure that you do not copy it to the output folder always. If you do, then only the data you inserted in the database from visual studio will exist. SOLUTION: Select never or if newer.
 
Hi TipGiver

Thanks for your prompt reply. I think you mean to select the mdf properties from the solution explorer and set its "Copy To Output Directory" value to "Do not copy" or "Copy if newer" (just making sure I fully understand - not making a point).

Is this correct?

Many thanks TipGiver. I'm very grateful for your help.
 
Hi TipGiver.

I did as you suggested and want to award you a star. However, what is the exact purpose of copying to the Output directory, and what do I need to do when I package the product for deployment? As I see it you end up with two copies. The original and the Output copy. Which is included in the deployment?

Your help is much appreciated.
 
Hi Sprowler,

sorry for my late post; I saw it now. Tnx for the Star.

Well yes i meant the Copy To Output Directory.
As for the setup project, after adding the primary output, on "file system on target machine" click "application folder". Right click -> add file, to add any file. As for the database: right click -> add -> project output and select "content files". You will see an entry added in the list after clicking ok. Click "Content file from <app_name>" and at the properties take a look at "Outputs" (click the "...").

The reason that the database is copied to the output directory is for accessing it. It is also between the source files but is like "prototype".
 
And a tip:

For debugging puproses click run from the visual studio. To see if the database works fine, do a build solution and run the exe from the bin directory by double-clicking. Suppose that the database file is on the root installation directory. The connection string (path) can be: Application.StartupPath & "\database1.mdf".

And last: If you add any file and want to access it when you hit run, you will propably want not to be copied in the output directory by selecting "Do not copy". You will have to copy and paste it on your own in the bin directory. Else, run once the app, then close it and then change the "Copy To Output Directory" from the default (Always copy) to "Do not copy".

That's from me.
Have a nice day!
 
Hi TipGiver

You're welcome for the Star, and thanks for the extra info. I'm a few weeks off the release, but i will need to test it soon, so thanks again.

Hope you have a nice day too!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top