connectionstrings 与appseting什么区别
1个回答
2014-12-29
展开全部
数据库的连接方法有2
1、在web.config 文件添加<appseting>
<add key="ConnectionString"
value="uid=;password=;database=;server=;">
</appseting>
调用时:
string connectionString=
System.Configuration.ConfigurationManager.AppSetings["ConnectionString"].ToString();
2、在web.config 文件添加<connectionStrings>
<add name="ConnectionString"
connectionString="Data Source=;Inital Catalog=;
Integrated Security=True;" ProviderName="System.Data.SqlClinet">
</connectionStrings>
3、创建“基于服务的数据库”
string dataDir = AppDomain.CurrentDomain.BaseDirectory;//获取应用程序当前目录
if(dataDir.EndsWith(@"\bin\Debug\")|| dataDir.EndsWith(@"\bin\Release\"))//此方法适用于控制台应用和winForm
{
dataDir=System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory",dataDir);
}
string strConnection = @"Data Source=.\SQLEXPRESS;AttachDBFileName=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True";
1、在web.config 文件添加<appseting>
<add key="ConnectionString"
value="uid=;password=;database=;server=;">
</appseting>
调用时:
string connectionString=
System.Configuration.ConfigurationManager.AppSetings["ConnectionString"].ToString();
2、在web.config 文件添加<connectionStrings>
<add name="ConnectionString"
connectionString="Data Source=;Inital Catalog=;
Integrated Security=True;" ProviderName="System.Data.SqlClinet">
</connectionStrings>
3、创建“基于服务的数据库”
string dataDir = AppDomain.CurrentDomain.BaseDirectory;//获取应用程序当前目录
if(dataDir.EndsWith(@"\bin\Debug\")|| dataDir.EndsWith(@"\bin\Release\"))//此方法适用于控制台应用和winForm
{
dataDir=System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory",dataDir);
}
string strConnection = @"Data Source=.\SQLEXPRESS;AttachDBFileName=|DataDirectory|\Database1.mdf;
Integrated Security=True;User Instance=True";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询