设置web.config以进行部署 - .Net

时间:2012-04-15 20:40:04

标签: c# deployment entity-framework-4 azure web-config

以下是我的web.config文件。我目前正在学习如何自己部署网站,因为我没有找到任何资源来学习如何使用连接到azure数据库的ADO.NET(实体框架/使用数据库模型)来部署网站。我创建了一个测试页面,它只是从特定的表中获取所有记录。完美的开发工作。我只是上传了web.config,default.aspx,default.aspx.cs和bin文件夹。我正在使用去爸爸。不幸的是,我收到一个错误,告诉我我没有连接到数据库!任何人都可以帮助我吗?? !!!

以下是我的错误和堆栈跟踪 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)

来源错误:

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: 


[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5061898
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) +341
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) +129
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) +239
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +195
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +232
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +33
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +524
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +479
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
   System.Data.SqlClient.SqlConnection.Open() +125
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +52

[EntityException: The underlying provider failed on Open.]
   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +161
   System.Data.EntityClient.EntityConnection.Open() +98
   System.Data.Objects.ObjectContext.EnsureConnection() +81
   System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +46
   System.Data.Objects.ObjectQuery`1.GetIListSourceListInternal() +13
   System.Data.Objects.ObjectQuery.System.ComponentModel.IListSource.GetList() +10
   System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember) +54
   System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName) +41
   System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +266
   System.Web.UI.WebControls.DataBoundControl.GetData() +4
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +24
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   WebApplication1._default.Page_Load(Object sender, EventArgs e) in C:\...\WebApplication1\default.aspx.cs:15
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

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

以下是我的web.config文件:

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <customErrors mode="Off"/>
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx" />
      </assemblies>
    </compilation>
  </system.web>
  <connectionStrings>
    <add name="xxx"  connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=xxx.database.windows.net;Initial Catalog=xxx;Persist Security Info=True;User ID=xxx;Password=xxx;MultipleActiveResultSets=True;Application Name=EntityFramework&amp;quot&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

2 个答案:

答案 0 :(得分:2)

GoDaddy可能会阻止出站连接。

联系他们的支持,或转到体面的主人。

答案 1 :(得分:1)

您是否尝试过配置SQL Azure防火墙以允许来自GoDaddy服务器的连接?

参考:http://msdn.microsoft.com/en-us/library/windowsazure/ee621782.aspx