有人可以简单地告诉我,如何在ASP.NET MVC 5项目中使用Oracle DB?我尝试过不同的文章,但没有得到明确的答案...

最佳答案

我认为这是执行此操作的简单方法:

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
                }
            }
        }

关于sql - 如何在没有 Entity Framework 的ASP.NET中使用Oracle数据库?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27551249/

10-10 09:01