Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to copy a Project from one stand-alone PC to another Expand / Collapse
Author
Message
Posted Tuesday, March 20, 2012 6:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, February 8, 2014 12:28 PM
Points: 22, Visits: 56
I thought this was going to be fairly straightforward, but it seems I am wrong !!!

I have written a small VS2010 C# Express program that accesses & updates a SQL Server 2008 R2 Express database on this PC. It's my home desktop machine & the idea is that I will be sending the Project to a friend in the UK for him to use on his stand-alone PC (a laptop I think, if that's at all relevant). So, to test how I would do this, I am trying to deploy it on my (again stand-alone) laptop here in Ireland.

From within VS2010 C# Express I clicked Project / Publish & followed the Wizard until it created a Folder called Application Files, a "ClickOnce Application Deployment Manifest" file and a Setup file all within my Published Projects Folder.

I assumed, presumably incorrectly, that this would create an executable version of my Program on the laptop, and install all the necessary .Net Framework & SQL Server software that it needed (assuming it wasn't already there) and the SQL Server Express database.

I then copied these 3 files to a USB and ran the Setup on my laptop. It installed a number of things and then came up with an MS .net Framework Error message saying "Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately. Cannot open database XXX requested by the login. The Login failed. The Login failed for user AAA"

Indeed, if I click Continue, the program starts to run and works until it tries to access the database, when I get the same message. Can somebody please explain clearly what I am doing wrong, or what I need to do to resolve this problem ?!?

I am especially confused by the fact that I can't find the database, which is named KAELC_DB.mdf on this PC, or any reference to it on the laptop after installation. This would obviously be a major contributor to the fact that I am getting database errors, but surely the database is part of the project ?!?!?
Post #1269502
Posted Tuesday, March 20, 2012 7:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 12,915, Visits: 32,074
nope. a database connection would be part of the project, not the database or the database service....the application "assumes" it's there.

you would typically parameterize the elements required for the connection string so they can be changed (server,database, username,password or use trusted connection) into either a config file, or so your applicaiton can allow the user to change it.


you would also want to provide a backup (not the .mdb ) so someone can restore the database on another server, change the connection string to point to their server, and then run the program.

does your app have something like that to change the connection?



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1269559
Posted Tuesday, March 20, 2012 8:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, February 8, 2014 12:28 PM
Points: 22, Visits: 56
OK, thank you, that makes sense.

No, my program is a Windows Form with multiple Tabs that allows the user to update the database (yearly maintenance) and then process the data on a regular (monthly-ish) basis, there is nothing like that screen of yours.

So I need to copy the database itself onto the USB when I deploy the Project, and create a small Setup program of my own that will copy the database, create a backup, amend the Config file and allow the "string" in the program to pick up the parameters of the new user's machine from that config file ?


Lowell (3/20/2012)
nope. a database connection would be part of the project, not the database or the database service....the application "assumes" it's there.

you would typically parameterize the elements required for the connection string so they can be changed (server,database, username,password or use trusted connection) into either a config file, or so your applicaiton can allow the user to change it.


you would also want to provide a backup (not the .mdb ) so someone can restore the database on another server, change the connection string to point to their server, and then run the program.

does your app have something like that to change the connection?

Post #1269581
Posted Tuesday, March 20, 2012 8:33 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 12,915, Visits: 32,074
gary.p.heath (3/20/2012)
OK, thank you, that makes sense.

No, my program is a Windows Form with multiple Tabs that allows the user to update the database (yearly maintenance) and then process the data on a regular (monthly-ish) basis, there is nothing like that screen of yours.

So I need to copy the database itself onto the USB when I deploy the Project, and create a small Setup program of my own that will copy the database, create a backup, amend the Config file and allow the "string" in the program to pick up the parameters of the new user's machine from that config file ?


I'd forgot the program of my own that will copy the database", and instead add documentation ("A SQL Server Instance of at least SQL Express is required") and instructions on how to restore the database.
then additional instructions on how to change the connection string to point to their server.

there are WAY to many variables in my opinion related to trying to create a program that will create the database...which comes right back down to the program needing to know where an exisitng database is (or installing SQL Express silently)


is your conneciton string hardcoded into the application?
Private Const SqlConnectionFormat As String =
"data source={0};
initial catalog={1};
user id={2};
password={3};
Trusted_Connection=False;
Application Name=Stormrage.ReportGrid.exe;"



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1269598
Posted Tuesday, March 20, 2012 8:47 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, February 8, 2014 12:28 PM
Points: 22, Visits: 56
Again, thank you Lowell ... having read and discussed a lot about VS2010 & SQL Server, I, too, think that there are way too many variables in areas of the project that seem totally unnecessary and superfluous for the Express versions. Yes, I can understand the need for all of them in production Server environments, but to make the Express versions so unnecessarily complicated seems a bit pointless to me ... still, I've used MS products for enough years to expect the "challenge" by now !!!

At the moment, my Connection String is as follows (I have tried a few hundred variations so far ...) :

string myDBlocation = @"Data Source=.\SQLEXPRESS;Initial Catalog=KAELC_DB;Integrated Security=True"; //Connect Timeout=30;User Instance=True";

... and I access it in various places like this :

using (SqlConnection myDB = new SqlConnection(myDBlocation))



Lowell (3/20/2012)
gary.p.heath (3/20/2012)
OK, thank you, that makes sense.

No, my program is a Windows Form with multiple Tabs that allows the user to update the database (yearly maintenance) and then process the data on a regular (monthly-ish) basis, there is nothing like that screen of yours.

So I need to copy the database itself onto the USB when I deploy the Project, and create a small Setup program of my own that will copy the database, create a backup, amend the Config file and allow the "string" in the program to pick up the parameters of the new user's machine from that config file ?


I'd forgot the program of my own that will copy the database", and instead add documentation ("A SQL Server Instance of at least SQL Express is required") and instructions on how to restore the database.
then additional instructions on how to change the connection string to point to their server.

there are WAY to many variables in my opinion related to trying to create a program that will create the database...which comes right back down to the program needing to know where an exisitng database is (or installing SQL Express silently)


is your conneciton string hardcoded into the application?
Private Const SqlConnectionFormat As String =
"data source={0};
initial catalog={1};
user id={2};
password={3};
Trusted_Connection=False;
Application Name=Stormrage.ReportGrid.exe;"

Post #1269614
Posted Tuesday, March 20, 2012 9:09 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 12,915, Visits: 32,074
I think you'll be fine if you just add a little flexibility into your application for handling the building of the connection string.

for example, what should happen if i wanted to install your application on my machine, for example?
I have two SQL server installations,A default 2008R2 and an instance named .\SQL2005
you don't want to force them to install another instance of SQL Express if they already have SQL, right?

or what if they have a SQL server on another, dedicated SQL machine and want to use that, instead of a local SQL Express instance?

you'd need to add a little somthing to your application to buidl the connectionstring based on those changes.
some crappy fake code as an example:, where i assume a couple of text fields were added to it.
string myDBlocation = @"
Data Source={0};
Initial Catalog={1};
Integrated Security=True";
//Connect Timeout=30;User Instance=True";
myDBlocation = string.Format(this.txtServerName.Text, this.txtDatabaseName.Text);



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1269634
Posted Tuesday, March 20, 2012 9:18 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, February 8, 2014 12:28 PM
Points: 22, Visits: 56
Lowell, you have made more sense and taught me more in the past hour than I have been able to learn in the past week over at CodeProject.com !!! Why didn't I ask here in the first place ?!?!?

I will give your suggestions a try & let you know how I get on, thanks yet again ...


Lowell (3/20/2012)
I think you'll be fine if you just add a little flexibility into your application for handling the building of the connection string.

for example, what should happen if i wanted to install your application on my machine, for example?
I have two SQL server installations,A default 2008R2 and an instance named .\SQL2005
you don't want to force them to install another instance of SQL Express if they already have SQL, right?

or what if they have a SQL server on another, dedicated SQL machine and want to use that, instead of a local SQL Express instance?

you'd need to add a little somthing to your application to buidl the connectionstring based on those changes.
some crappy fake code as an example:, where i assume a couple of text fields were added to it.
string myDBlocation = @"
Data Source={0};
Initial Catalog={1};
Integrated Security=True";
//Connect Timeout=30;User Instance=True";
myDBlocation = string.Format(this.txtServerName.Text, this.txtDatabaseName.Text);

Post #1269641
Posted Tuesday, March 20, 2012 9:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:23 AM
Points: 12,915, Visits: 32,074
gary.p.heath (3/20/2012)
Lowell, you have made more sense and taught me more in the past hour than I have been able to learn in the past week over at CodeProject.com !!! Why didn't I ask here in the first place ?!?!?

I will give your suggestions a try & let you know how I get on, thanks yet again ...

Comments like that, where I end up knowing I helped someone help themselves, are exactly why I volunteeer some time here.
Thank you very much for the feedback!


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1269669
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse