您的位置:首页 > 数据库

如何获得配置文件中,连接数据库的连接字符串

2013-09-12 13:23 489 查看
在ASP .net MVC的应用程序中,需要在web.config中配置连接字符串来连接数据库,在部署到具体的服务器上的时候,就需要查看指定服务器上SQL Server的连接字符串,下图是在windows server 2008中的SQL Server 2008的界面。









下面是web.config文件:



1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3   For more information on how to configure your ASP.NET application, please visit
4   http://go.microsoft.com/fwlink/?LinkId=152368 5 -->
6 <configuration>
7 <connectionStrings>
8 <add name="ApplicationServices" connectionString="data source=WIN-WZQI6CNOKTP\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
9 <add name="SaveenergyConnectionString" connectionString="Data Source=WIN-WZQI6CNOKTP\SQLEXPRESS;Initial Catalog=saveenergy;Persist Security Info=True;User ID=sa;Password=kiss_123*KISS_321" providerName="System.Data.SqlClient"/>
10 <add name="SaveenergyEntities" connectionString="metadata=res://*/Models.Enerysaving.csdl|res://*/Models.Enerysaving.ssdl|res://*/Models.Enerysaving.msl;provider=System.Data.SqlClient;provider connection string="Data Source=WIN-WZQI6CNOKTP\SQLEXPRESS;Initial Catalog=saveenergy;Persist Security Info=True;User ID=sa;Password=kiss_123*KISS_321;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
11 </connectionStrings>
12 <system.web>
13 <compilation targetFramework="4.0">
14 <assemblies>
15 <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
16 <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
17 <add assembly="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
18 <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
19 </assemblies>
20 </compilation>
21 <authentication mode="Forms">
22 <forms loginUrl="~/Account/LogOn" timeout="2880"/>
23 </authentication>
24 <membership>
25 <providers>
26 <clear />
27 <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SaveenergyConnectionString" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="2" applicationName="/"/>
28 </providers>
29 </membership>
30 <profile>
31 <providers>
32 <clear />
33 <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SaveenergyConnectionString" applicationName="/"/>
34 </providers>
35 </profile>
36 <roleManager enabled="true">
37 <providers>
38 <clear />
39 <add connectionStringName="SaveenergyConnectionString" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
40 </providers>
41 </roleManager>
42 <pages>
43 <namespaces>
44 <add namespace="System.Web.Mvc"/>
45 <add namespace="System.Web.Mvc.Ajax"/>
46 <add namespace="System.Web.Mvc.Html"/>
47 <add namespace="System.Web.Routing"/>
48 </namespaces>
49 </pages>
50 </system.web>
51 <system.webServer>
52 <validation validateIntegratedModeConfiguration="false"/>
53 <modules runAllManagedModulesForAllRequests="true"/>
54 <directoryBrowse enabled="false"/>
55 </system.webServer>
56 <runtime>
57 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
58 <dependentAssembly>
59 <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
60 <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
61 </dependentAssembly>
62 </assemblyBinding>
63 </runtime>
64 </configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: