【发布时间】:2010-02-16 18:36:18
【问题描述】:
我有一个 SQL Server 2005 机器,用于合并复制到 SQL Server CE 3.0。出版商、出版商、发行商、IIS均已设置完毕。
在我的应用程序中,我尝试使用以下代码同步数据库:
//TODO: Change for production
//***************************
string localDBPath = @"C:\Documents and Settings\Robert\Desktop\MyDB.sdf";
//***************************
SqlCeReplication replicator = new SqlCeReplication();
replicator.InternetUrl = "http://myWebServer/sqlcesa30.dll";
replicator.Publisher = "mySqlServer";
replicator.PublisherDatabase = "myDatabase";
replicator.PublisherSecurityMode = SecurityType.NTAuthentication;
replicator.Publication = "myPublication";
replicator.Subscriber = Dns.GetHostName();
replicator.SubscriberConnectionString = @"Data Source=" + localDBPath;
try
{
// Check if the database file already exists
if (!System.IO.File.Exists(localDBPath))
{
// Add a new subscription and create the local database file
replicator.AddSubscription(AddOption.CreateDatabase);
}
// Transfer the initial snapshot of data if this is the first time this is called.
// Subsequent calls will transfer only the changes to the data.
replicator.Synchronize();
}
catch (SqlCeException ex)
{
// Display any errors in message box
MessageBox.Show(ex.Message);
}
finally
{
// Dispose of the SqlCeReplication object, but don't drop the subscription
replicator.Dispose();
}
不幸的是,此代码在“replicator.Synchronize”行失败,并显示以下错误消息:
无法使用提供的连接信息连接到 SQL Server。 SQL Server 不存在,访问被拒绝,因为 IIS 用户不是 SQL Server 上的有效用户,或者密码不正确。
这个错误信息对我来说不是很清楚,我没有地方去寻找它的原因。有什么想法吗?
【问题讨论】:
标签: c# sql-server iis replication sql-server-ce