出现此错误“ORA-06413:连接未打开”
我使用的是 Visual Studio 2010 和 Oracle 10g。操作系统:Windows 7 家庭基本版。如果我在 Visual Studio 2005 中使用以下代码,我将得到正确的输出。但在 Visual Studio 2010 中我收到错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
OracleConnection con = new OracleConnection("uid=scott;pwd=tiger;data source=");
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
string name1, pass1;
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd = new OracleCommand("Select* from tb1 where name='" + TextBox1.Text + "'and pass='"+TextBox2.Text + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
name1 = dr[0].ToString();
pass1 = dr[1].ToString();
}
if (name1 == TextBox1.Text && pass1 == TextBox2.Text)
{
Response.Redirect("Home.aspx");
}
else
{
MessageBox.Show("Incorrect user name or password");
}
}
}
I am using visual studio 2010 and Oracle 10g. Operating system: Windows 7 home basic. If I use the following code in visual studio 2005, I am getting a correct output. But in Visual Studio 2010 I get an error
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
using System.Windows.Forms;
public partial class Default2 : System.Web.UI.Page
{
OracleConnection con = new OracleConnection("uid=scott;pwd=tiger;data source=");
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
string name1, pass1;
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd = new OracleCommand("Select* from tb1 where name='" + TextBox1.Text + "'and pass='"+TextBox2.Text + "'", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
name1 = dr[0].ToString();
pass1 = dr[1].ToString();
}
if (name1 == TextBox1.Text && pass1 == TextBox2.Text)
{
Response.Redirect("Home.aspx");
}
else
{
MessageBox.Show("Incorrect user name or password");
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这可能是定义连接的
tnsnames.ora
的问题。您可以使用以下连接字符串省略
tnsnames.ora
:It could be a problem with the
tnsnames.ora
, where your connection is defined.You can omit
tnsnames.ora
with this connection string:从页面加载中删除打开的连接并在执行之前添加以下内容:
Remove the connection open from the page load and add the following before the execute:
请在您的硬盘上搜索名为
tnsnames.ora
的文件,并在此处发布该文件的内容。还有一些提示:
向
default2.aspx
添加一个 div。并调用:
检查名称和密码两次,一次在 SQL 语句中,一次在代码中。这是更好的:
Please search your hard drive for a file named
tnsnames.ora
, and post the contents of the file here.And some tips:
Add a div to your
default2.aspx
.and call:
Check name and password twice, one time in the SQL statement, and one time in the code. This is better:
您尚未将连接分配给该命令,在执行该命令之前您需要如下所示的内容:
You have not assigned the connection to the command, you need something like below before you execute the command:
对比 2010 年:
我想分享一个经验,当时我通过 WCF 服务汇集 oracel 连接并在开发服务器上托管该 WCF。收到错误“ORA-06413:连接未打开”。找不到网络搜索的实际帮助。最后,我在生产服务器上部署了 WCF 的编译版本。当我从我的应用程序中使用 WCF 服务时,它对我有用......
希望这可以帮助面临同样问题的人......
VS 2010:
i would like to share anexperience, when i was pooling oracel connection via WCF service and hosting that WCF on development server. getting that error "ORA-06413: Connection not open". could not find actual help for web serach. Finally, i deployed the compiled version of WCF on production server. when i used that WCF service from my application it worked for me....
Hope this could help someone facing the same issue...