会话超时后ASP.NET MVC 4应用程序数据库连接问题

时间:2013-06-19 09:38:15

标签: asp.net asp.net-mvc database hosting

我有一个使用.NET framework 4.5的MVC 4网站,起初工作正常。它允许我登录并开始我的业务添加,删除和编辑记录。因此,显然最初在没有问题的情况下连接到数据库。但是,如果我将其暂停一段时间并稍后返回,然后单击指向显示数据库中数据的页面的链接,则会出现以下错误:

The SSE Provider did not find the database file specified in the connection string. At the configured trust level (below High trust level), the SSE provider cannot automatically create the database file.

该网站在我的本地主机上运行正常,但在我在线托管时却没有。我使用共享主机。我已经在网上进行了广泛的搜索,发现很多人都得到了同样的错误,但他们似乎没有一个最初有效的网站然后突然停止工作。我在网上找到的解决方案有以下几点:

add these two lines to your web.config file
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=p3swhsql-v15.shr.phx3.secureserver.net; Initial Catalog=DatabaseName; User ID=****; Password='****';"/>


by default the .net site is trying to find your database in the local filesystem in this case would be the app_data subfolder under the wwwroot directory. simply removing the connectionstring and replacing it with the database connection solves the issue. My example utilizes an SQL db on godaddy's server. however i'm sure you can replace the connection string with the appropriate string for your connection. good luck and i hope this helps anyone that may be having this issue

我的程序似乎正在做的是在我第一次登录时使用在线数据库,然后在会话超时后恢复尝试在本地文件系统中使用数据库。这非常令人沮丧。我的web.config文件如下所示:

<connectionStrings>
    <remove name="DefaultConnection"/>
    <add name="DefaultConnection" connectionString="Data Source=winsqls01.cpt.wa.co.za;Initial Catalog=SportFantasySA;Persist Security Info=True;User ID=*****;Password=*****" providerName="System.Data.SqlClient"/>
  </connectionStrings>

请帮忙。我迫不及待地想要这个工作。我知道它无法在托管空间中创建sql express数据库,这就是为什么我在托管公司的服务器上使用数据库的连接字符串。

2 个答案:

答案 0 :(得分:0)

如果您已将其托管在Godaddy上,请转到连接字符串

<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" connectionStringName="LocalSqlServer"
    ..other attributes here... /></providers>

<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
    connectionString="Data Source=xxxx; Initial Catalog=xxx; User ID=xxx; Password=xxx;"
    providerName="System.Data.SqlClient" />

答案 1 :(得分:0)

您使用共享主机吗?如果您使用共享主机,基本上您无法使用会话,因为它会影响其他客户端站点。但是您可以使用cookie作为替代方案,或者您可以使用ASP.NET会话状态:

希望它有所帮助。 :)

相关问题