string connectionstring = "Data Source='192.168.1.201/fstest';user=DNSNMP;password=oracle;";//写连接串 MessageBox.Show(connectionstring);
// string MySqlConnection = "Provider=OraOLEDB.Oracle;Data Source='192.168.1.201/fstest'; user id=DBSNMP;password=oracle"; OracleConnection orconn = new OracleConnection(connectionstring);
try
{
orconn.Open();
OracleCommand cmd = orconn.CreateCommand();
cmd.CommandText = "select * from t_user where username='+username+'";
MessageBox.Show(cmd.CommandText);
OracleDataReader odr = cmd.ExecuteReader();
while (odr.Read())
{
MessageBox.Show(odr.GetOracleString(1).ToString()); }
odr.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{ orconn.Close();
}
}
// string MySqlConnection = "Provider=OraOLEDB.Oracle;Data Source='192.168.1.201/fstest'; user id=DBSNMP;password=oracle"; OracleConnection orconn = new OracleConnection(connectionstring);
try
{
orconn.Open();
OracleCommand cmd = orconn.CreateCommand();
cmd.CommandText = "select * from t_user where username='+username+'";
MessageBox.Show(cmd.CommandText);
OracleDataReader odr = cmd.ExecuteReader();
while (odr.Read())
{
MessageBox.Show(odr.GetOracleString(1).ToString()); }
odr.Close();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{ orconn.Close();
}
}
下个OO4O,里面有ORALCE 提供的所有驱动,装了就好,
但是建议你用ODP.NET ,oo4o的一种,为.NET专门开发的,再到WWW.CONNECTIONSTRINGS.COM,找到对就的连接字符串
这个就是OLEDB的连接字符串。
但你的Source='192.168.1.201/fstest'是错的
应该建立正确的TNSNAMES.ORA,然后用Source=DATABASE NAME.所以建议你用ODP.NET 这样就不用建TNSNAMES.ORA了。
装了一个ORACLE的客户端软件,这样能连接上~~还是要谢谢你~~
服务器代码:
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectString"];
OracleConnection orconn = new OracleConnection(ConnectionString);
试试
using(oracledataadapter adp=new oracledataadapter("select * from tablename","connectionStr"))
{
adp.fill(ds);
}
大概这样了!
source=实例名
或者用IBatisNet动态配置Oracle连接
参考FortuneBase,参考地址www.cnblogs.com/mail-ricklee