Connecting Error to Remote Oracle XE database using ASP.NET
Posted
by imsatasia
on Stack Overflow
See other posts from Stack Overflow
or by imsatasia
Published on 2010-05-03T15:46:13Z
Indexed on
2010/05/03
15:48 UTC
Read the original article
Hit count: 326
Hello,
I have installed Oracle XE on my Development machine and it is working fine.
Then I installed Oracle XE client on my Test machine which is also working fine and I can access Development PC database from Browser.
Now, I want to create an ASP.Net application which can access that Oracle XE database. I tried it too, but it always shows me an error on my TEST machine to connect database to the Development Machine using ASP.Net.
Here is my code for ASP.Net application:
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = GetConnectionString();
OracleConnection connection = new OracleConnection(connectionString);
connection.Open();
Label1.Text = "State: " + connection.State;
Label1.Text = "ConnectionString: " + connection.ConnectionString;
OracleCommand command = connection.CreateCommand();
string sql = "SELECT * FROM Users";
command.CommandText = sql;
OracleDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string myField = (string)reader["nID"];
Console.WriteLine(myField);
}
}
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file.
return "User Id=System;Password=admin;Data Source=(DESCRIPTION=" +
"(ADDRESS=(PROTOCOL=TCP)(HOST=myServerAddress)(PORT=1521))" +
"(CONNECT_DATA=(SERVICE_NAME=)));";
}
© Stack Overflow or respective owner