How to copy a Project from one stand-alone PC to another

  • 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 ?!?!?

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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?

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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;"

  • 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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • 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 :crying: ?!?!?

    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);

  • 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 :crying: ?!?!?

    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


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply