网站部署时远程数据库连接失败
问题描述:
我使用GoDaddy的在线数据库管理器创建了一个数据库,但是我在部署我的ASP.NET项目后无法查询它。在我的本地机器上,一切正常。我有一个充满数据的数据网格。网站部署时远程数据库连接失败
这里是我跟着从我的本地机器上查询数据库的步骤:
- 创建一个Silverlight应用程序。在ASP.NET Web应用程序中承载SL项目。启用WCF RIA服务
- 将新实体模型添加到ASP.NET项目。实体连接字符串点到远程数据库
- 添加域服务的ASP.NET项目
- 添加一个数据网格,以Silverlight项目通过使用左手侧的数据源选项卡
当我运行这个应用程序,我可以在我的本地机器上填充数据。当我使用Publish Web向导进行FTP部署时,该应用程序已成功上传,因为我可以通过FTP应用程序查看这些文件。
我在做什么错?我听说SL应用程序需要一个clientaccesspolicy.xml文件。使用WCF RIA服务时是否需要?我是否需要更改我的Web.config文件?这里是VS自动生成的配置文件:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler"
type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="(Entities Here)" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=(Source Here);Initial Catalog=(Catalog Here);User ID=(ID Here);Password=(Password Here);MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
答
听说SL应用程序需要一个clientaccesspolicy.xml文件。使用WCF RIA服务时是否需要?
是的。您必须明确允许跨域访问。它在本地工作,因为您的网站和数据库服务器位于同一个“域” - 本地计算机上。
clientaccesspolicy.xml
文件必须位于承载服务的域的根目录中。
您还可以使用crossdomain.xml
- Silverlight支持两者。
只需添加在根目录下的文件,但我仍然无法查看应用程序。我在浏览器中遇到了“服务器错误”/“应用程序”运行时错误。 – user246392 2011-04-19 12:09:35