最近接触ASP.NET,毫无经验。所以想请这里的老大们指教指教。具体情况是这样的。我点电脑上装了ORACLE客户端,想访问局域网内的另一台电脑上的ORACLE数据库,但不知道怎么连接。网上看了些资料但是还是没解决。下面是我的连接代码。希望大大们不吝赐教。先谢谢了!
在web.config中是这样添加的
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) (HOST=172.16.133.73)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=KF;Password=kf;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
其实具体意思也不是很清楚 特别是那个Port=1521 连接端口只有这个吗?
在login.aspx.cs中代码是这样的
protected void Button1_Click(object sender, EventArgs e)
{
// String app_connstr = System.Configuration.ConfigurationManager.AppSetting["SocutDataLink"].ToString
();
string ConnectionString = "Data Source=orcl;Persist Security Info=True;User ID=KF;Password=kf;Unicode=True;";
OracleConnection conn = new OracleConnection(ConnectionString);
try
{
conn.Open();
comm = new OracleCommand("select * from KF.USERS where USERNAME='"
+ TextBox1.Text + "'and USERPWD='" + TextBox2.Text + "'", conn);
drLogin = comm.ExecuteReader();
while (drLogin.Read())
{
Response.Redirect("http://www.hao123.com/");
}
drLogin.Close();
}
catch (Exception ee)
{
Response.Write(ee.Message); //如果有错误,输出错误信息
}
finally
{
conn.Close(); //关闭连接
} }
情况就是这么个情况,恳求大大们多多指教。再次感谢!我是新手没什么积分,所以对不起大家了。
在web.config中是这样添加的
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP) (HOST=172.16.133.73)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=KF;Password=kf;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
其实具体意思也不是很清楚 特别是那个Port=1521 连接端口只有这个吗?
在login.aspx.cs中代码是这样的
protected void Button1_Click(object sender, EventArgs e)
{
// String app_connstr = System.Configuration.ConfigurationManager.AppSetting["SocutDataLink"].ToString
();
string ConnectionString = "Data Source=orcl;Persist Security Info=True;User ID=KF;Password=kf;Unicode=True;";
OracleConnection conn = new OracleConnection(ConnectionString);
try
{
conn.Open();
comm = new OracleCommand("select * from KF.USERS where USERNAME='"
+ TextBox1.Text + "'and USERPWD='" + TextBox2.Text + "'", conn);
drLogin = comm.ExecuteReader();
while (drLogin.Read())
{
Response.Redirect("http://www.hao123.com/");
}
drLogin.Close();
}
catch (Exception ee)
{
Response.Write(ee.Message); //如果有错误,输出错误信息
}
finally
{
conn.Close(); //关闭连接
} }
情况就是这么个情况,恳求大大们多多指教。再次感谢!我是新手没什么积分,所以对不起大家了。
打开管理器看看
<add name="connectionString" connectionString="server=a;user id=sys;password=sys;"
providerName="System.Data.OracleClient" />
string str= "Data Source=test;User Id=sys;Password=sya;DBA Privilege=SYSDBA;"
OleDbConnection conn=new OleDbConnection(str);
<add name="ConnStrOracle" connectionString="Data Source=xyz_user;User ID=hnfnuweb;Password=abc#123%^&;Unicode=True" providerName="System.Data.OracleClient"/>
</connectionStrings>
while (drLogin.Read())
{
Response.Redirect("http://www.hao123.com/");
}
2.配置连接字符串:
<connectionStrings>
<add name="ZhjqConnectionString" providerName="System.Data.OracleClient" connectionString="Data Source=LocalDBID;user id=sxupload;password=sxupload;min pool size=2;max pool size=10"/>
</connectionStrings>注: localDBID换成你本地配置的客户端的服务名
string ConnectionString = "Data Source=login;Persist Security Info=True;User ID=KF;Password=kf;Unicode=True;";
OracleConnection conn = new OracleConnection(ConnectionString);
其中login是在tnsnames.ora中设置的连接名,userid和password是登录数据库的用户名和密码 我的login是这样的:
login =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.133.73)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = orcl)
)
)
Button1_Click事件代码:
protected void Button1_Click(object sender, EventArgs e)
{ string ConnectionString = "Data Source=login;User ID=KF;Persist Security Info=True;Password=kf;Unicode=True;";
OracleConnection conn = new OracleConnection(ConnectionString);
conn.Open();//open database
try
{ comm = new OracleCommand("select * from KF.USERS where USERNAME='"
+ TextBox1.Text + "'and USERPWD='" + TextBox2.Text + "'", conn);
drLogin = comm.ExecuteReader();
while (drLogin.Read())
{
Response.Redirect("http://www.hao123.com/");
}
drLogin.Close();
}
catch (Exception ee)
{
Response.Write(ee.Message); //如果有错误,输出错误信息
}
finally
{
conn.Close(); //关闭连接
} }