请问连接数据库的配置文件改怎么写
<?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<configSections>
该处应该如何写???
</configSections>
</configuration>
------解决方案-------------------- <PWebConfiguration>
<!-- example -->
<add key= "PWeb.ConnectionString " value= "user id=aaa;data source=datasource;password=bbb " />
</PWebConfiguration>
------解决方案--------------------楼上正解。
------解决方案--------------------想怎么写都可以阿
------解决方案-------------------- <?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<configSections>
<add key= "ConnectionString " value= "user id=aaa;data source=datasource;password=bbb " />
</configSections>
</configuration>
然后读 "ConnectionString "就行了。
------解决方案-------------------- <add key= "connectionstring " value= "server=电脑IP;database=数据库名称;uid=sa;password=sa; "/>
--------------
取:
ConfigurationManager.AppSettings[ "connectionstring "]
------解决方案-------------------- <add key= " " value= " " /> 不是放在configSections节里面的,而是放在appSettings节里面,只有放在这里,你才能用以下方法来取:
ConfigurationManager.AppSettings[ " "];
------解决方案-------------------- <?xml version= "1.0 " encoding= "utf-8 " ?>
<configuration>
<connectionStrings>
<add name= "sqlConnectionString " connectionString= "Data Source=.;Initial Catalog=GSIM;Integrated Security=True "/>
</connectionStrings>
</configuration>
添加应用----System.Configuration
再using System.Configuration;
得到连接字符串:ConfigurationManager.ConnectionStrings[ "sqlConnectionString "].ConnectionString.ToString();
------解决方案-------------------- <connectionStrings>
<add name= "sqlConnectionString " connectionString= "Data Source=.;Initial Catalog=GSIM;Integrated Security=True "/>