web.config 中到一个 SQL DB 的两个连接字符串在调试中工作,但在发布时不工作

Posted

技术标签:

【中文标题】web.config 中到一个 SQL DB 的两个连接字符串在调试中工作,但在发布时不工作【英文标题】:Two connection strings in web.config to one SQL DB work in debug but not when published 【发布时间】:2019-10-14 09:06:50 【问题描述】:

我正在尝试将 asp 标识添加到一个非常基本的 MVC 站点,该站点当前包含来自 SQL 数据库的单个表。

SQL 是作为 ADO.NET 实体数据模型添加的,使用数据库中的 EF 设计器,我可以从我的 MVC 站点(在本地开发和发布后)毫无问题地进行读写。

然后我添加了 asp.net 身份,这添加了一个有效的本地数据库文件。

然后我尝试将身份表迁移到我的主 SQL 服务器,这样我只需要维护一个数据库(网站的托管和 SQL 数据库都使用同一个提供商)。

我已经设法在主 SQL 数据库中创建了表,并在我的 web.config 中添加了第二个连接字符串,以允许 asp 身份和我现有的 edmx 设置工作(如果我尝试通过 EF 运行 asp 身份连接字符串我收到错误“实体类型 ApplicationUser 不是当前上下文模型的一部分。”)。然后我删除了本地数据库文件以确保。

在我的客户端(使用两个连接字符串)上进行测试时,我可以创建帐户、登录和退出并按预期使用 asp.identity,还可以看到主 SQL 数据库中的身份表正在填充。我还可以使用我的通用 EF 连接来读取和写入 DB 的核心 MVC 站点。

但是,当我发布到主站点时,无论我调用身份还是 EF DB 函数,我都会收到错误

错误。处理您的请求时出错。

显示在渲染页面上/内联(我尝试在 web.config 中打开自定义错误,但这似乎没有给我更多详细信息。)

我的两个连接字符串如下所示(我假设这是问题所在?)我还需要web.config 中的其他内容吗?还是我遗漏了一些基本的东西?

<connectionStrings>
   <add name="BDIdentityString" connectionString="Data Source=IPADDRESS; Initial Catalog=DBNAME; User ID=USERNAME; Password=PASSWORD; Connect Timeout=60;" providerName="System.Data.SqlClient" />
   <add name="BDString" connectionString="metadata=res://*/Models.DBENTITYNAME.csdl|res://*/Models.DBENTITYNAME.ssdl|res://*/Models.DBENTITYNAME.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=IPADDRESS;initial catalog=DBNAME;user id=USERNAME;password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

更新:

所以我终于得到了自定义错误(认为我在某处有错字),错误发布在下面。作为测试,我使用我的项目的备份副本在不引入身份的情况下再次测试 EF DB 查询 - 发布并实时测试。再次,这一切都按预期工作。然后我恢复了我当前的构建并添加了身份并回到相同的问题。 (EF的连接字符串在项目的两个版本中保持不变)

为了清楚起见,我正在使用 fasthosts.co.uk,在我的测试中,我通过从我的客户端读取和写入由 fasthosts 托管的实时 SQL 数据库来做到这一点。与发布到 fasthosts 时没有身份的备份版本一样,仍然能够连接和读取/写入 SQL DB。

我正在使用他们的 Momentum 包,因此包含了从我拥有的本地 IIS 服务器生成的所需的 machineKey。此密钥在不带身份的版本 1 和带身份的版本 2 中都存在。

我也尝试将以下内容添加到 AssemblyInfo.cs

[assembly: AllowPartiallyTrustedCallers]
[assembly: SecurityRules(SecurityRuleSet.Level1)]

(fasthosts 推荐的 AllowPartiallyTrustedCallers 用于安全异常描述类型错误)

关闭 customerErrors 后,我会得到两种不同的响应,这取决于我是通过身份调用数据库还是从我的 MVC 代码中的 EF 调用调用数据库。错误如下:

EF 错误:

erver Error in '/' Application.

Operation could destabilize the runtime. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Security.VerificationException: Operation could destabilize the runtime.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[VerificationException: Operation could destabilize the runtime.]
   System.Data.Entity.Core.Metadata.Edm.FacetDescription.Validate(String declaringTypeName) +70
   System.Data.Entity.Core.Metadata.Edm.FacetDescription..ctor(String facetName, EdmType facetType, Nullable`1 minValue, Nullable`1 maxValue, Object defaultValue, Boolean isConstant, String declaringTypeName) +103
   System.Data.Entity.Core.SchemaObjectModel.FacetDescriptionElement.CreateAndValidateFacetDescription(String declaringTypeName) +115
   System.Data.Entity.Core.SchemaObjectModel.TypeElement.ResolveTopLevelNames() +119
   System.Data.Entity.Core.SchemaObjectModel.Schema.ResolveTopLevelNames() +206
   System.Data.Entity.Core.SchemaObjectModel.Schema.Resolve() +16
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +553
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, IList`1& schemaCollection) +156
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest(XmlReader xmlReader, String location, Boolean checkForSystemNamespace, Schema& schema) +139
   System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader reader) +75
   System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor(XmlReader reader) +116
   System.Data.Entity.SqlServer.SqlProviderManifest..ctor(String manifestToken) +37
   System.Data.Entity.SqlServer.<>c.<GetDbProviderManifest>b__29_0(String s) +25
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +73
   System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest(String versionHint) +124
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +55

[ProviderIncompatibleException: The provider did not return a ProviderManifest instance.]
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +186
   System.Data.Entity.Core.Metadata.Edm.Loader.InitializeProviderManifest(Action`3 addError) +312
   System.Data.Entity.Core.Metadata.Edm.Loader.OnProviderManifestTokenNotification(String token, Action`3 addError) +33
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader) +97
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader) +184
   System.Data.Entity.Core.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader) +185
   System.Data.Entity.Core.SchemaObjectModel.SchemaElement.Parse(XmlReader reader) +76
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader) +37
   System.Data.Entity.Core.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation) +739
   System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation) +58
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +340
   System.Data.Entity.Core.Metadata.Edm.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) +158
   System.Data.Entity.Core.Metadata.Edm.Loader..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver) +127
   System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer`2& cachedCTypeFunction) +131
   System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) +223
   System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) +88
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass9_1.<GetMetadataWorkspace>b__1() +14
   System.Lazy`1.CreateValue() +429
   System.Lazy`1.LazyInitValue() +158
   System.Lazy`1.get_Value() +79
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass9_1.<GetMetadataWorkspace>b__4() +9
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection(Func`1 itemCollectionLoader) +16
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass12_0.<.ctor>b__3() +21
   System.Lazy`1.CreateValue() +429
   System.Lazy`1.LazyInitValue() +158
   System.Lazy`1.get_Value() +79
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required) +95
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace) +12
   System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner) +46
   System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory) +575
   System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() +65
   System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() +21
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +506
   System.Data.Entity.Internal.InternalContext.Initialize() +20
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
   System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +62
   System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) +108
   System.Data.Entity.DbSet`1.Add(TEntity entity) +72
   HotBrewCrew.Controllers.HomeController.Register(interested_parties fromForm) in C:\Users\ewilson\Documents\Development\HotBrewCrew\HotBrewCrew\Controllers\HomeController.cs:26
   lambda_method(Closure , ControllerBase , Object[] ) +100
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +166
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58
   System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9839161
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

身份错误

Server Error in '/' Application.

Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.]
   Microsoft.AspNet.Identity.Owin.SignInManager`2.PasswordSignInAsync(String userName, String password, Boolean isPersistent, Boolean shouldLockout) +0
   HotBrewCrew.Controllers.<Login>d__11.MoveNext() in C:\Users\ewilson\Documents\Development\HotBrewCrew\HotBrewCrew\Controllers\AccountController.cs:74
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass8_0.<BeginInvokeAsynchronousActionMethod>b__1(IAsyncResult asyncResult) +17
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58
   System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9839161
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3928.0 

更新 2

这可能是 fasthosts 的信任问题。我刚刚建立了一个启用身份的开箱即用 MVC 站点。将连接字符串更改为指向 SQL DB - 再次在开发环境中工作(详细信息从主项目开发测试中注册),但在没有其他更改的情况下实时推送时失败。

我会努力询问托管服务提供商,但我不是 100% 相信这是我唯一/或实际的问题,因为 EF 在没有身份的情况下工作,只是没有在项目中安装身份。

【问题讨论】:

发布实际的异常文本。你试过调试你的代码吗?问题可能只是由于 IP 不正确 “数据源”可能需要服务器名称和实例。使用 SQL Server Management Studio (SSMS) 并检查登录窗口。服务器和实例将在登录窗口中。还要检查凭据是否为 ​​Windows。要使用远程数据库(不在同一台机器上),您必须能够在两台不同的 Windows 机器之间进行连接。所以两台机器需要在同一个组中才能。所以你必须创建一个windows组。最好使用 Windows 凭据而不是用户名和密码。在本地和远程计算机上创建用户组帐户并将所有用户添加到组。 感谢您初步了解 - 我已经设法让 csustomErrors 正常工作并更新了帖子 - 开发和实时 SQL DB 是相同的。这适用于从开发环境到实时数据库,而不是从实时环境到实时数据库(实时环境和数据库提供者是同一个提供者) 这个暗中的刺说编辑你的 web.config cslanet.com/old-forum/12744.html 这似乎是一个更好解释的答案。如果我能理解它***.com/questions/27742902/… 【参考方案1】:

正如预期的那样,限制是 https://www.fasthosts.co.uk/ - 移动我的网站时没有代码更改(除了 SQL 连接字符串以反映新的 SQL 服务器),提供程序 https://hostinguk.net/ 网站运行没有问题。

【讨论】:

确实,.NET 的最新版本需要完全信任。许多低预算的共享主机提供商仍然出于某种未知原因阻止了这一点。我记得看到一个声明说没有理由这样做。

以上是关于web.config 中到一个 SQL DB 的两个连接字符串在调试中工作,但在发布时不工作的主要内容,如果未能解决你的问题,请参考以下文章

在SQL中 如何实现不同数据库的两张表的同步

错误的sqlite3 db.lock在VS中阻止Web部署

将两个表中查出的两列信息放在同一个表中

应用Web.Config配置网站

如何在web.config里面设置页面跳转问题

ASP.NET中WEB.config连接网络服务器SQL 2005数据库,代码怎么写?