I have interesting error. This error happens only in remote server, my function works properly in my local computer.
here is my code;
public bool GecisKontrol(KisiModel km)
{
bool varmi = false;
//today without hours and minutes
string bugun = DateTime.Now.ToString("dd/MM/yyyy");
using (OracleConnection con = new OracleConnection())
{
con.ConnectionString = "Data Source=(DESCRIPTION="
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=xxx.xxx.xxx.x)(PORT=1521))"
+ "(CONNECT_DATA=(SERVICE_NAME=xxxxxx)));"
+ "User Id=xxxxxx;Password=xxxx;";
con.Open();
using (OracleCommand cmd = new OracleCommand())
{
cmd.Connection = con;
if (km.GECISDURUM == 0)
{
//Normaly, i store variable ZAMAN as dd/MM/yyyy HH:mm
//But i need to compare as date, because of this i used TRUNC(ZAMAN)
cmd.CommandText = "select * from YENI_OTOMASYON_GECISLER WHERE TCKIMLIK = :1 and YEMEKHANEID = :2 and OGUNID = :3 and TRUNC(ZAMAN) = :4 and GECISDURUM = :5";
cmd.Parameters.Add(new OracleParameter("1",
OracleDbType.Varchar2,
km.TCKimlik,
ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("2",
OracleDbType.Varchar2,
YemekHaneID,
ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("3",
OracleDbType.Varchar2,
OGUNID,
ParameterDirection.Input));
//I am sure, problem is here...
cmd.Parameters.Add(new OracleParameter("4",
OracleDbType.Date,
Convert.ToDateTime(bugun),
ParameterDirection.Input));
cmd.Parameters.Add(new OracleParameter("5",
OracleDbType.Varchar2,
km.GECISDURUM,
ParameterDirection.Input));
}
using (OracleDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
varmi = true;
}
else
{
varmi = false;
}
}
}
con.Close();
}
return varmi;
}
When i run this code in my local computer, i never get an error. It gives error only in remote server. I don't have enough information about remote server. That server admin don't share information. By the way, The column that name "ZAMAN" is DATE.
Strip the time off your c# datetime but keep it as a date. By making bugun
a string and pushing it into a date type sql parameter you're forcing oracle to parse your string back to a date, and it's failing because the server uses a different locale to your machine
DateTime bugun = DateTime.Now.Date;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.