LocalDB 'Cannot Open Database' erro

Dear Experts;
I'm working with a Microsoft walkthru to Synchroinze a SQL Server database and a LocalDB database.
I've created and provisioned both dbs successfully, and was able to execute the synchronization project successfully ... once.
When I try to run the synchronization a second time (I added a record to LocalDB and was testing upload sync); I get a 'Cannot open database' exception (full detail attached).

It complains about login, but I was able to provision the localDB w/ the same connection string; and synchronization ran the first time, so I'm not sure login is really the issue.

Below is my code (C#). I'm using LocalDB ver 11.0, and SQL Server 2008.
Any guidance is appreciated.
Thank you!

**** code *** (error occurs on SyncOperationStatistics syncstats = syncOrchestrator.Synchronize(); line)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Synchronization;
using Microsoft.Synchronization.Data;
using Microsoft.Synchronization.Data.SqlServer;
using Microsoft.Synchronization.Data.SqlServerCe;

namespace ExecuteExpressSync
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;AttachDbFilename=c:\SyncSQLServerAndSQLCompact\database\SyncExpressDB.mdf;Integrated Security=True");
            //SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;Initial Catalog=SyncExpressDB;Integrated Security=True");

            SqlConnection serverConn = new SqlConnection("Data Source=<MyServer>.com; Initial Catalog=SyncDB; User ID = <UN>; Password = <PW>;");

            // create the sync orchestrator
            SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

            // set local proivder of orchestrator to sync provider associated with the
            // ProductsScope in the SyncExpressDB express client database
            syncOrchestrator.LocalProvider = new SqlSyncProvider("ProductsScope", clientConn);

            // set the remote provider of orchestrator to a server sync provider associated with
            // the ProductsScope in the SyncDB server database
            syncOrchestrator.RemoteProvider = new SqlSyncProvider("ProductsScope", serverConn);

            // set the direction of sync session to upload and download TODO: change to download only
            syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload;

            // subscribe for errors that occur when applying changes to the client
//**** Error occurs on next line ****
            SyncOperationStatistics syncstats = syncOrchestrator.Synchronize();

            // print statistics
            Console.WriteLine("Start Time: " + syncstats.SyncStartTime);
            Console.WriteLine("Total Changes Uploaded: " + syncstats.UploadChangesTotal);
            Console.WriteLine("Total Changes Downloaded: " + syncstats.DownloadChangesTotal);
            Console.WriteLine("Complete Time: " + syncstats.SyncEndTime);
            Console.WriteLine(string.Empty);

        }

        static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)
        {
            // display conflict type
            Console.WriteLine(e.Conflict.Type);

            // display error message
            Console.WriteLine(e.Error);
        }
    }
}
k heitzsoftware developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

anarki_jimbelSenior DeveloperCommented:
Try to close your connections before you proceed with another try.

Or use "using" keyword, the "using" block will call conn.Close() automatically:

using (DbConnection conn = new DbConnection())
{
    // do stuff with database
}

Open in new window


It is also a good practice to put all your db access code into a try - catch block.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
k heitzsoftware developerAuthor Commented:
Just what I needed! Thanks!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.