appconfig的读写中connection string怎么写
1个回答
展开全部
1.先在程序中导入包using System.Configuration;
2.或是在右边项目名中添加外键引用 System.Configuraton;
xml文件配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configruations>
</configurations>
<connectionStrings>
<add name="DataBaseOwner" (数据库拥有者) connectionString="dbo"(类似sql)>
<add name="MySchoolConnectionString" connectionString=" Data Source=。;Initial Catalog=MySchool; User ID=sa; Password=12345 "
providerName=" System.Data.SqlClient "
</connectionStrings>
</configuration>
从配置文件中读取数据库连接字符串
private readonly string connString=ConfigurationManager.ConnectionStrings["MySchoolConnectionString "].ToString();
private readonly string dboOwner=ConfigurationManager.ConnectionStrings[" DataBaseOwner "].ToString();
2.或是在右边项目名中添加外键引用 System.Configuraton;
xml文件配置如下:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configruations>
</configurations>
<connectionStrings>
<add name="DataBaseOwner" (数据库拥有者) connectionString="dbo"(类似sql)>
<add name="MySchoolConnectionString" connectionString=" Data Source=。;Initial Catalog=MySchool; User ID=sa; Password=12345 "
providerName=" System.Data.SqlClient "
</connectionStrings>
</configuration>
从配置文件中读取数据库连接字符串
private readonly string connString=ConfigurationManager.ConnectionStrings["MySchoolConnectionString "].ToString();
private readonly string dboOwner=ConfigurationManager.ConnectionStrings[" DataBaseOwner "].ToString();
追问
配置文件读写数据库连接在哪写
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询