如何在没有实体框架的ASP.NET中使用Oracle数据库?

时间:2022-09-07 15:13:56

Can some one tell me in a simple way how can i use a Oracle db in my ASP.NET MVC 5 project? i tired of search in all sites and i don't have a clear answer...

有人可以用一种简单的方式告诉我如何在ASP.NET MVC 5项目中使用Oracle数据库?我厌倦了所有网站的搜索,我没有一个明确的答案......

1 个解决方案

#1


4  

I think this is the simple way to do this:

我认为这是一种简单的方法:

using System.Data.OracleClient;

        public string GetConnectionString()
        {
            String connString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=YourHostName)(PORT=YourPort))(CONNECT_DATA=(SERVICE_NAME=YourServiceName)));uid=YourUserId;pwd=YourPassword;";
            return connString;
        }

        public void ConnectingToOracle()
        {
            string connectionString = GetConnectionString();
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;

                connection.Open();

                OracleCommand command = connection.CreateCommand();
                string sql = "select * from MyDatabase where name like '%John Paul%'";
                command.CommandText = sql;

                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string myField = (string)reader["address"]; //Get the address of John Paul
                }
            }
        }

#1


4  

I think this is the simple way to do this:

我认为这是一种简单的方法:

using System.Data.OracleClient;

        public string GetConnectionString()
        {
            String connString = "SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=YourHostName)(PORT=YourPort))(CONNECT_DATA=(SERVICE_NAME=YourServiceName)));uid=YourUserId;pwd=YourPassword;";
            return connString;
        }

        public void ConnectingToOracle()
        {
            string connectionString = GetConnectionString();
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;

                connection.Open();

                OracleCommand command = connection.CreateCommand();
                string sql = "select * from MyDatabase where name like '%John Paul%'";
                command.CommandText = sql;

                OracleDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string myField = (string)reader["address"]; //Get the address of John Paul
                }
            }
        }