将 Oracle 数据库用于默认的 ASP.NET MVC 应用程序 [英] Using Oracle database for the default ASP.NET MVC application

查看:31
本文介绍了将 Oracle 数据库用于默认的 ASP.NET MVC 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使默认的 ASP.NET MVC 应用程序使用远程 Oracle 数据库.我已经设置了 oracle 客户端并且可以从服务器资源管理器访问远程数据库.我尝试从

更改连接字符串

 <添加名称=应用服务"connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"providerName="System.Data.SqlClient"/></connectionStrings>

<添加名称=应用服务"connectionString="Data Source=orcl;Persist Security Info=True;User ID=username;Password=mypassword;Unicode=True"providerName="Oracle.DataAccess.Client"/></connectionStrings>

我使用了服务器资源管理器 > 数据连接 > orcl.instance 中的连接字符串

创建新用户时,我在 AccountModels.cs 中收到以下错误

尝试初始化 System.Data.SqlClient.SqlConnection 对象时出错.为连接字符串提供的值可能是错误的,或者它可能包含无效的语法.参数名称:connectionString

知道我在这里遗漏了什么吗?

看起来 AccountModels.cs 中的以下代码段使用了 System.Data.SqlClient.SqlConnection.我如何使用 ODP 版本.

 公共类 AccountMembershipService : IMembershipService{私人只读 MembershipProvider _provider;...}

解决方案

你必须使用 ODP.NET API 而不是 SqlClient 提供程序.System.Data.SqlClient 类仅适用于 Microsoft SQL 服务器数据库.

Oracle 文章:用于 ASP.NET 安装的 Oracle Providers>

I am trying to make the default ASP.NET MVC application use a remote Oracle database. I have set up the oracle client and can access the remote database from Server Explorer. I tried changing the connection string from

 <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

to

<connectionStrings>
    <add name="ApplicationServices"
         connectionString="Data Source=orcl;Persist Security Info=True;User ID=username;Password=mypassword;Unicode=True"
         providerName="Oracle.DataAccess.Client" />
  </connectionStrings>

I used the connection string from Server Explorer > Data Connection > orcl.instance

When creating a new user, I am getting the following error in AccountModels.cs

An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax.
Parameter name: connectionString

Any idea what am I missing here?

EDIT: Looks like the following snippet in AccountModels.cs uses System.Data.SqlClient.SqlConnection. How can I use the ODP version.

 public class AccountMembershipService : IMembershipService
    {
        private readonly MembershipProvider _provider;
        ...
    }

解决方案

You have to use ODP.NET API instead of SqlClient provider. The System.Data.SqlClient classes are for Microsoft SQL server database only.

EDIT:

Oracle article : Oracle Providers for ASP.NET Installation

这篇关于将 Oracle 数据库用于默认的 ASP.NET MVC 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆