views:

185

answers:

1

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=)));";
        }
A: 

Don't you need a service name to connect to in your connection string? E.g.,

return "User Id=System;Password=admin;Data Source=(DESCRIPTION=" +
                    "(ADDRESS=(PROTOCOL=TCP)(HOST=myServerAddress)(PORT=1521))" +
                    "(CONNECT_DATA=(SERVICE_NAME=myDBServiceName)));";
DCookie
I tried it to but still not working. For the information, I'm using Windows server 2008 - 64bit and VS 2008. My code is working fine with Windows 7 32 bit.
imsatasia
It would be helpful to know the exact error message/code you're getting.
DCookie
If it is XE, then it should be SERVICE_NAME=XE
Gary