c#操作oracle数据库,异常信息:12710:TNS:连接超时
刚学winform和oracle,写了个小的登录窗口测试能否连上oracle数据库。界面和代码如下using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void reset_Click(object sender, EventArgs e)
{
username.Text = "";
userpwd.Text = "";
}
private void login_Click(object sender, EventArgs e)
{
string user = username.Text.Trim();
string pwd = userpwd.Text.Trim();
const string constring = "data source=EMR;User=scott;Password=tiger;";
string sql = String.Format("select count(*) from scott.ADMIN where username = '{0}' and userpwd = '{1}'", user, pwd);
OracleConnection connection = new OracleConnection(constring);
try
{
connection.Open();
OracleCommand command = new OracleCommand(sql, connection);
Int32 num = Convert.ToInt32(command.ExecuteScalar());
if (num>0)
MessageBox.Show("登录成功");
else
MessageBox.Show("登录失败");
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
finally
{
connection.Close();
}
}
}
}
运行后输入用户名密码后,弹窗显示了异常信息:
在命令行登录scott账户是没问题的,而且在navicat for oracle中也能建立scott账户的连接。
data source 数据源我也配置了,
我电脑现在的情况是,已经安装了oracle数据库,但是没安装oracle的客户端,这个没有影响吧??
困扰我一天了都,求大神赐教啊!! oracle c# --------------------编程问答-------------------- Google .NET连接Oracle --------------------编程问答-------------------- 要配置TNS,Google搜索什么叫“ORACLE TNS”
或者你把完整的TNS字符串写到连接字符串中。
你后面配置的ODBC数据源在这里是多余的,OracleClient是不使用它的。
补充:.NET技术 , C#