k heitz
asked on
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.Synchroni ze(); 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.SqlSe rver;
using Microsoft.Synchronization. Data.SqlSe rverCe;
namespace ExecuteExpressSync
{
class Program
{
static void Main(string[] args)
{
SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;AttachDbFi lename=c:\ SyncSQLSer verAndSQLC ompact\dat abase\Sync ExpressDB. mdf;Integr ated Security=True");
//SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;Initial Catalog=SyncExpressDB;Inte grated 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.LocalProv ider = new SqlSyncProvider("ProductsS cope", clientConn);
// set the remote provider of orchestrator to a server sync provider associated with
// the ProductsScope in the SyncDB server database
syncOrchestrator.RemotePro vider = new SqlSyncProvider("ProductsS cope", serverConn);
// set the direction of sync session to upload and download TODO: change to download only
syncOrchestrator.Direction = SyncDirectionOrder.UploadA ndDownload ;
// subscribe for errors that occur when applying changes to the client
//**** Error occurs on next line ****
SyncOperationStatistics syncstats = syncOrchestrator.Synchroni ze();
// print statistics
Console.WriteLine("Start Time: " + syncstats.SyncStartTime);
Console.WriteLine("Total Changes Uploaded: " + syncstats.UploadChangesTot al);
Console.WriteLine("Total Changes Downloaded: " + syncstats.DownloadChangesT otal);
Console.WriteLine("Complet e Time: " + syncstats.SyncEndTime);
Console.WriteLine(string.E mpty);
}
static void Program_ApplyChangeFailed( object sender, DbApplyChangeFailedEventAr gs e)
{
// display conflict type
Console.WriteLine(e.Confli ct.Type);
// display error message
Console.WriteLine(e.Error) ;
}
}
}
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.Synchroni
using System;
using System.Collections.Generic
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Microsoft.Synchronization;
using Microsoft.Synchronization.
using Microsoft.Synchronization.
using Microsoft.Synchronization.
namespace ExecuteExpressSync
{
class Program
{
static void Main(string[] args)
{
SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;AttachDbFi
//SqlConnection clientConn = new SqlConnection(@"Data source = (LocalDb)\v11.0;Initial Catalog=SyncExpressDB;Inte
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.LocalProv
// set the remote provider of orchestrator to a server sync provider associated with
// the ProductsScope in the SyncDB server database
syncOrchestrator.RemotePro
// set the direction of sync session to upload and download TODO: change to download only
syncOrchestrator.Direction
// subscribe for errors that occur when applying changes to the client
//**** Error occurs on next line ****
SyncOperationStatistics syncstats = syncOrchestrator.Synchroni
// print statistics
Console.WriteLine("Start Time: " + syncstats.SyncStartTime);
Console.WriteLine("Total Changes Uploaded: " + syncstats.UploadChangesTot
Console.WriteLine("Total Changes Downloaded: " + syncstats.DownloadChangesT
Console.WriteLine("Complet
Console.WriteLine(string.E
}
static void Program_ApplyChangeFailed(
{
// display conflict type
Console.WriteLine(e.Confli
// display error message
Console.WriteLine(e.Error)
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER