I have this code in Transaction.cs
using (TransactionScope scope = new TransactionScope())
{
// Setup nhibernate configuration
Configuration config = new Configuration();
config.SetProperty("hibernate.connection.connection_string", GlobalVar.TRUECONNSTRING);
config.SetProperty("hibernate.command_timeout", "3600");
config.AddAssembly(typeof(ProductionMovein).Assembly);
// Setup nhibernate session
ISessionFactory factory = config.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();
//Recalculate Number
PairData pairCabang = (PairData)comboCabang.SelectedItem;
textNo.Text = FormFunction.getNumber(2, pairCabang.key, dtpTanggal.Value);
// Insert data
try
{
//ProductionMoveIn
ProductionMovein productionMoveIn = new ProductionMovein();
productionMoveIn.Nomor = textNo.Text;
session.Save(productionMoveIn);
transaction.Commit();
session.Close();
}
catch (Exception ex)
{
transaction.Rollback();
session.Close();
MessageBox.Show(ex.InnerException.Message);
return 1;
}
scope.Complete();
}
And the error is started from
textNo.Text = FormFunction.getNumber(2, pairCabang.key,
dtpTanggal.Value);
i have this code in Formfunction.cs
public static string getNumber(int formID, int cabangID, DateTime date)
{
string formNumber = "";
string strQuery = "";
formNumber += formNames[formID, 0] + "/" + + date.ToString("yy") + date.ToString("MM") + "/";
// Setup nhibernate configuration
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.SetProperty("hibernate.connection.connection_string", GlobalVar.TRUECONNSTRING);
config.SetProperty("hibernate.command_timeout", "3600");
config.AddAssembly(typeof(Login).Assembly);
//// Setup nhibernate session
ISessionFactory factory = config.BuildSessionFactory();
ISession session = factory.OpenSession();
strQuery = "SELECT MAX(REVERSE(SUBSTRING(REVERSE(a.Nomor), 1, 5))) as 'latest' FROM " + formNames[formID, 1] +
" a WHERE a.cabang = " + cabangID +
" AND YEAR(a.tanggal) = '" + date.ToString("yyyy");
Object result = session.CreateSQLQuery(strQuery)
.AddScalar("latest", NHibernateUtil.Int32)
.UniqueResult();
session.Close();
int nRow;
if (result == null)
nRow = 0;
else
nRow = (int)result;
formNumber += (nRow + 1).ToString("d5");
return formNumber;
}
I have tried to change the Server to 10.10.7.10 (my ip) and it works. but, when i change to other ip, it cannot open connection.
I have tried to turn on msdtc on my computer and the other server i tried to connect, but still get the same error.


Can anybody help me how to solve this error?
Which database are you using? (I’ve assumed MS SQL)
Can you post the exception detail please?
Here’s an approach.
using (TransactionScope)/scope.Completeand try connect to the remote database – i.e. to ensure that your
local Sql client is configured for TCP/IP, the remote server allows
remote TCP/IP connections (usually port 1433), and that your login
credentials and access are correct.
you reinstate the TransactionScope, but then remove the NHibernate
transaction, then DTC might not be required at all. Also note that
TransactionScopes default to Read Serializable isolation –
TransactionScope functions
Ensure that DTC is configured on both your PC and the Server to
.
allow remote connections etc –
You also need to tackle firewall issues
DTC firewall requirements?
EDIT
By default, SQL Express isn’t open to remote connections – on the remote server, you will need to enable TCP/IP on SQL Configuration Manager, open up the firewall for 1433 / 1434, and as @Özgür mentions, ensure that the SQL the browser service is running (or change your instance name, or change your connection string to use ip, port). More on this here : http://www.sevenforums.com/system-security/58817-remote-access-sql-server-express-2008-windows-7-a.html