2013-04-08 8 views
5

私はASP.Net MVC 4に新しいアプリケーションをデプロイしました。私はSQL Server 2008 R2 SQL Expressではない)。MVC 4でSQL Server Expressデータベースファイルの自動作成エラー - 私はSQL Server Expressを使用したくない

最初の10分間はうまくいきました。その後、コードを少し変更して再デプロイしました。私はない SQL Server Expressを使用して操作を行い、

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

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.

SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:

しかし:私はSimpleMembershipを使用するページにアクセスしようとするたびに

は今、私はこのエラーを取得します。次のように私のweb.configでは、私はすべての接続文字列を設定しました:

<add name="ApplicationServices" 
    connectionString="Server=myServer;Database=myDB;User Id=myUserID;Password=myPWD;" 
    providerName="System.Data.SqlClient" /> 

<add name="ApplicationServices" 
    connectionString="Server=myServer;Database=myDB;User Id=myUserID;Password=myPWD;" 
    providerName="System.Data.SqlClient" /> 

なぜそれがSQL ServerのEXPRESSデータベースを作成しようとし続けるのでしょうか?

+0

接続文字列名は、データベースコンテキストと同じである必要があります。 http://stackoverflow.com/questions/5346926/code-first-specify-database-name – AaronLS

+1

を参照してください申し訳ありませんが、あなたの問題を誤解している可能性があります。私はまずあなたがEFコードを使用していると仮定しました。 – AaronLS

+1

あなたはこれを解決しましたか?私はまったく同じエラーに直面しています.. – Chatumbabub

答えて

4

まだこの問題がありますか?また、なぜApplicationServicesが2回リストされていますか?

私は同じことをしばらくやりました。メンバーシップとロールのためにweb.configのconfigが欠けていました。

<membership defaultProvider="AspNetSqlMembershipProvider"> 
    <providers> 
    <clear /> 
    <add name="AspNetSqlMembershipProvider" 
     type="System.Web.Security.SqlMembershipProvider" 
     connectionStringName="ApplicationServices" 
     enablePasswordRetrieval="false" 
     enablePasswordReset="true" 
     requiresQuestionAndAnswer="false" 
     requiresUniqueEmail="false" 
     maxInvalidPasswordAttempts="5" 
     minRequiredPasswordLength="6" 
     minRequiredNonalphanumericCharacters="0" 
     passwordAttemptWindow="10" 
     applicationName="Test" /> 
    </providers> 
</membership> 
<roleManager enabled="true" defaultProvider="SqlRoleManager"> 
    <providers> 
    <add name="SqlRoleManager" 
     type="System.Web.Security.SqlRoleProvider" 
     connectionStringName="ApplicationServices" 
     applicationName="Test" /> 
    </providers> 
</roleManager> 
4

このエラーが発生したとき、それは簡単であることが判明しました。私は最終的に私の_Layout.cshtmlでUser.IsInRole("role")を参照していたが、Request.isAuthenticatedの後にあることを知った。私のコードは@if (Request.isAuthenticated && User.IsInRole("role"))のように見えました。基本的に私がホームページで署名されていないと、IsInRole()の呼び出し(これは単純なメンバーシップを初期化する必要があります。そうでなければ、ここで言及したエラーが発生します。一人ひとり_layoutファイルを拡張するビューを使用して認証されていないユーザーを持つことができ、コントローラは、[InitializeSimpleMembership]。または単純なメンバーを初期化するために、様々な方法のいずれかを持っている必要があります。

ので

namespace ProjectName.Controllers 
{ 
    [InitializeSimpleMembership] 
    public class HomeController : Controller { 
... 

のようなものまた、私はしばしばCtrl + F5を押してアプリケーションを起動し、その後 "Rebuild Solution"を使用します。ルートではないページをリフレッシュしたとき私はルートホームページを呼び出すまで、私はエラーが発生します。その時点で、すべてが再び働き始めるでしょう。

これがあなたや誰かを助けることを望みます。私は少なくとも1時間か2時間頭を叩いた。

関連する問題