I have installed sql server 2008 R2 in two systems, from this one system act as a server and another is client.
I need to copy product from server system database to client system database
In my web.config
<connectionStrings>
<add name="DBConnection" connectionString="Data Source=SERVER-PC\SQLEXPRESS2008;Initial Catalog=POS;Integrated Security=False;User Id=sa;Password=sql2008;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="DBConnection1" connectionString="Data Source=CLIENT-PC\SQLEXPRESS2008;Initial Catalog=POS;Integrated Security=False;User Id=sa;Password=sql2008;Connection Timeout=1;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
Here My Coding
using (TransactionScope trnsScope = new TransactionScope())
{
try
{
List<Master_ProductBLL> lstProduct = new List<Master_ProductBLL>();
//My First SQL Connection For Server
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString))
{
connection.Open();
//Here I can get All Products from Server Database
lstProduct = Master_ProductBLL.GetMaster_ProductBLLs(DBAction.Status.Active, "");
connection.Dispose();
}
//My Second SQL Connection For Client
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection1"].ConnectionString))
{
connection.Open();
//Here I have save my Server Product into Client SQL Server
foreach (Master_ProductBLL item in lstProduct)
{
item.Save(true);
}
connection.Dispose();
}
trnsScope.Complete();
trnsScope.Dispose();
}
catch (TransactionException ex)
{
trnsScope.Dispose();
throw ex;
}
}
It shows an Error like MSDTC on server 'CLIENT-PC\SQLEXPRESS2008' is unavailable
Unable to get the address of the distributed transaction coordinator for the server, from the server. Is DTC enabled on the server?
I have google it and find the following details
- go to Services. (START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES)
- Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start.
- make this service to run Automatically for solving this issue permanently
I have done the above steps both server and client.
But Still have an error