oracle与c#交互的时候出错
我的代码:privatestaticstringconnstr=@"DataSource=(WMSIN=(DESCRIPTION=(ADDRESS_LIST=(ADDRE...
我的代码:private static string connstr = @"Data Source=(WMSIN =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.60.13.180)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = smdb)
)
));User Id=prog;Password=prog";
但是调试的时候老是报错:ORA-12533: TNS: 非法的 ADDRESS 参数。。大侠、求解决 展开
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.60.13.180)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = smdb)
)
));User Id=prog;Password=prog";
但是调试的时候老是报错:ORA-12533: TNS: 非法的 ADDRESS 参数。。大侠、求解决 展开
2个回答
2013-04-18
展开全部
这些配置在tnsnames.ora文件里面的才对。
tnsnames.ora文件里面是这样的
# tnsnames.ora Network Configuration File: E:\oracle\product\10.2.0\db_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = PC-201312PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
给你个最简单的c#执行oracle查询和增删改的代码。
public static string mConnStr = "Data Source=ORCL;User Id=aaa;Password=aaa;";
public static bool ExecuteNonSql(string vSql)
{
bool vIsOk = false;
OracleConnection conn = new OracleConnection(mConnStr);
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = vSql;
try
{
conn.Open();
if (cmd.ExecuteNonQuery() > 0)
{
vIsOk = true;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return vIsOk;
}
public static DataSet ExecuteSql(string vSql)
{
DataSet vDs = new DataSet();
OracleConnection conn = new OracleConnection(mConnStr);
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = vSql;
OracleDataAdapter oda = new OracleDataAdapter(cmd);
try
{
conn.Open();
oda.Fill(vDs);
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return vDs;
}
2013-04-18
展开全部
这是SERVICE_NAM的问题,你的SERVICE_NAM可能不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询