C# web.config asp.net中的oracle数据库连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16432576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 00:59:41  来源:igfitidea点击:

oracle database connection in web.config asp.net

c#asp.netoracle

提问by sys_debug

I know I can create a connection string in the c# class itself, but I am trying to avoid doing that. I want to create the connection in the web.config, which I read is more secure. Nevertheless I couldn't find any example that has the following attributes specified:

我知道我可以在 c# 类本身中创建一个连接字符串,但我试图避免这样做。我想在 web.config 中创建连接,我读到它更安全。尽管如此,我还是找不到任何指定了以下属性的示例:

  • Host name
  • Port
  • SID
  • Username
  • Password
  • Connection Name
  • 主机名
  • 港口
  • 标准识别码
  • 用户名
  • 密码
  • 连接名称

Could anyone help please with creating this in webconfig? I am connecting to oracle DB.

有人可以帮忙在 webconfig 中创建这个吗?我正在连接到 Oracle DB。

采纳答案by Josh Leeder

Here is the template:

这是模板:

     <connectionStrings>
        <add name="{ConnectionName}" 
        connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;" 
        providerName="Oracle.DataAccess.Client"/>
     </connectionStrings>

Here is one of mine - minus a real TNS name and username and password:

这是我的一个 - 减去真实的 TNS 名称以及用户名和密码:

    <add name="MSOL" connectionString="Data Source={TNS_NAME};User ID={username};Password={password};pooling=true;min pool size=5;Max Pool Size=60" providerName="Oracle.DataAccess.Client"/>

回答by user2110717

It may can help u....

它可能会帮助你......

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort))(CONNECT_DATA=(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

http://www.connectionstrings.com/oracle

http://www.connectionstrings.com/oracle

You can investigate what the connection string should be like:

您可以调查连接字符串应该是什么样的:

1) Create an empty text file in windows explorer and rename it to X.UDL
2) Double click on it and the datalink provider dialog will appear.
3) Select the provider tab. Find the provider for your data access method and click next.
4) Select your source
5) Test the connection and save it.
6) Compare the contents of X.UDL with your connections string.

1) 在 Windows 资源管理器中创建一个空文本文件并将其重命名为 X.UDL
2) 双击它,将出现数据链接提供程序对话框。
3) 选择提供者选项卡。找到您的数据访问方法的提供者,然后单击下一步。
4) 选择您的来源
5) 测试连接并保存。
6) 将 X.UDL 的内容与您的连接字符串进行比较。

回答by Nico de Wit

After adding the connection string to the web.config you can use the following:

将连接字符串添加到 web.config 后,您可以使用以下内容:

System.Configuration.ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

to retrieve the connection string.

检索连接字符串。