连接字符串重写 [英] connection string retrivation

查看:86
本文介绍了连接字符串重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。

i从aapcofig文件中恢复连接字符串有一些问题。

请帮助我。

im给出以下代码。



< in config =file =>



hello.
i have some problem with retriving connection string from aapcofig file.
please help me.
i m giving codes below.

<in config="" file="">

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <connectionStrings>

    <add name="con" connectionString="Server=.;Database=prince;Integrated Security=true"/>

  </connectionStrings>

</configuration>











(代码背后)




string connection = ConfigurationManager.ConnectionStrings [con]。ConnectionString;

但它无效。

i也用过






(Code Behind)


string connection = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
but its not working.
i have also used

using System.Configuration;
using System.Data.SqlClient;





请帮忙我

问候

dibyaranjan



please help me
regards
dibyaranjan

推荐答案

大家好



首先,我想要两个共享,web.config和app.config是两个不同的文件,使用不同的角色第一个用于Web应用程序,第二个用于窗口应用....



有两种方法可以通过Integrated Security =true或通过设置用户ID和密码来实现连接字符串...



你必须尝试这个吗



Hi all

1st of all i want two share that web.config and app.config is two different files that use different different role 1st one for web application and 2nd one is for window application ....

there is two way to achieve connection string by Integrated Security ="true" or by setting User ID and Password...

you have to try this one

<configuration>
  <appsettings>
    <add key="con" value="server=.;User Id=root;password=password;database=prince;" />
  </appsettings>
</configuration>





很乐意提供帮助。



happy to help.


这里是连接字符串的方式





< appsettings>

< connectionstrings>







here is the way to give connection string


<appsettings>
<connectionstrings>



<configuration>
<pre lang="HTML">
 <add name="mmisConnectionString" connectionString="server=localhost;User Id=root;password=password;database=mmis" providerName="MySql.Data.MySqlClient" />





< / connectionStrings>



< / configuration>



</connectionStrings>

</configuration>


如果对于上述所有解决方案,您的代码仍无法正常工作



您需要在解决方案资源管理器中为参考文件夹添加参考文件来进行System.Configuration
If for all above solution your code is still not working then

You need to add referece to reference folder in solution explorer for System.Configuration


这篇关于连接字符串重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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