C# 取得自己Hostname 及 IP
C# 要取得自己的 hostname 及所有介面的ip,可以使用以下的方法:
using System.Net;
// 取得本機hostname的方法
localhostname = Environment.UserDomainName;
//取得遠端hostname得到IP的方法
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostname);
//得到遠端IP個數
int ipaddrnum = ipHostInfo.AddressList.GetLength(0);
// ipHostInfo 中有所有的 IPAddress
foreach (IPAddress ipaddress in ipHostInfo.AddressList){}
// 把字串轉成IP的方法
IPAddress ip = IPAddress.Parse ( "x.x.x.x" );
搜尋此網誌
2014年9月29日 星期一
2014年9月25日 星期四
SQL Server 2005 如何解開 Lock
使用 select object_id('TABLE_NAME') 或是 select object_name('OBJECT_ID') 去查出該 Lock 是屬於哪個 Table
使用 sp_lock 去查詢被 Lock 的資料有哪些, 因為他不會直接列出 Table 名稱, 所以可透過上述取得OBJID
接下來針對SPID去下指令即可
kill 81
2014年9月3日 星期三
db command
using System.Data.SqlClient;
using System.Configuration;
using Oracle.DataAccess.Client;
using System.Collections;
public static SqlConnection CPCIS1Conn = new SqlConnection(ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString());
public static OracleConnection ORASRVConn = new OracleConnection(ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString());
public static ArrayList tSQL = new ArrayList();
public static ArrayList oSQL = new ArrayList();
protected DataTable GetDataSQL(string Command, string TableName)
{
DataTable Dt = new DataTable();
CPCIS1Conn.Close();
CPCIS1Conn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
SqlCommand cmd = new SqlCommand(sTranstionSql, CPCIS1Conn);
SqlDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
CPCIS1Conn.Close();
return Dt;
}
protected DataTable GetDataORACLE(string Command, string TableName)
{
DataTable Dt = new DataTable();
ORASRVConn.Close();
ORASRVConn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
OracleCommand cmd = new OracleCommand(sTranstionSql, ORASRVConn);
OracleDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
ORASRVConn.Close();
return Dt;
}
protected bool WriteDataSQL(ArrayList SQL)
{
try
{
SqlCommand DBCommand = new SqlCommand();
SqlTransaction DBTransaction;
SqlConnection DBConnection = new SqlConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction("SQLTransaction");
DBCommand.Connection = DBConnection;
DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
tSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
tSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
tSQL.Clear();
throw new Exception(ex.Message);
}
}
protected bool WriteDataORACLE(ArrayList SQL)
{
try
{
OracleCommand DBCommand = new OracleCommand();
OracleTransaction DBTransaction;
OracleConnection DBConnection = new OracleConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction();
DBCommand.Connection = DBConnection;
//DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
//DBTransaction.Rollback();
oSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
oSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
oSQL.Clear();
throw new Exception(ex.Message);
}
}
using System.Configuration;
using Oracle.DataAccess.Client;
using System.Collections;
public static SqlConnection CPCIS1Conn = new SqlConnection(ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString());
public static OracleConnection ORASRVConn = new OracleConnection(ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString());
public static ArrayList tSQL = new ArrayList();
public static ArrayList oSQL = new ArrayList();
protected DataTable GetDataSQL(string Command, string TableName)
{
DataTable Dt = new DataTable();
CPCIS1Conn.Close();
CPCIS1Conn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
SqlCommand cmd = new SqlCommand(sTranstionSql, CPCIS1Conn);
SqlDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
CPCIS1Conn.Close();
return Dt;
}
protected DataTable GetDataORACLE(string Command, string TableName)
{
DataTable Dt = new DataTable();
ORASRVConn.Close();
ORASRVConn.Open();
try
{
Dt.TableName = TableName;
string sTranstionSql = Command;
OracleCommand cmd = new OracleCommand(sTranstionSql, ORASRVConn);
OracleDataReader sdr = cmd.ExecuteReader();
Dt.Load(sdr);
}
catch (Exception ex)
{
ex.ToString();
}
ORASRVConn.Close();
return Dt;
}
protected bool WriteDataSQL(ArrayList SQL)
{
try
{
SqlCommand DBCommand = new SqlCommand();
SqlTransaction DBTransaction;
SqlConnection DBConnection = new SqlConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringCPCIS1"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction("SQLTransaction");
DBCommand.Connection = DBConnection;
DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
tSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
tSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
tSQL.Clear();
throw new Exception(ex.Message);
}
}
protected bool WriteDataORACLE(ArrayList SQL)
{
try
{
OracleCommand DBCommand = new OracleCommand();
OracleTransaction DBTransaction;
OracleConnection DBConnection = new OracleConnection();
DBConnection.ConnectionString = ConfigurationSettings.AppSettings["ConncetionStringORASRV01"].ToString();
DBConnection.Open();
DBCommand = DBConnection.CreateCommand();
DBTransaction = DBConnection.BeginTransaction();
DBCommand.Connection = DBConnection;
//DBCommand.Transaction = DBTransaction;
try
{
for (Int32 i = 0; i < SQL.Count; i++)
{
DBCommand.CommandText = SQL[i].ToString();
DBCommand.ExecuteNonQuery();
}
DBTransaction.Commit();
//DBTransaction.Rollback();
oSQL.Clear();
return true;
}
catch (Exception ex)
{
DBTransaction.Rollback();
oSQL.Clear();
throw new Exception(ex.Message);
}
}
catch (Exception ex)
{
oSQL.Clear();
throw new Exception(ex.Message);
}
}
訂閱:
文章 (Atom)