我在 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();
}
并且错误是从
textNo.Text = FormFunction.getNumber(2, pairCabang.key, dtpTanggal.Value);
我在 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;
}
我试图将服务器更改为 10.10.7.10(我的 ip)并且它可以工作。但是,当我更改为其他 ip 时,它无法打开连接。我尝试在我的计算机和我尝试连接的另一台服务器上打开 msdtc,但仍然出现相同的错误。
谁能帮我解决这个错误?