1

VisualStudio2012とSQLServerExpress2012を使用しています。「インターネットアプリケーション」テンプレートを使用してMVC4Webアプリケーションを作成しました。

(テンプレートのMDFではなく)SQL Server2012Expressのインスタンスで既存のデータベースを使用したかったのです。代わりにローカルSQLExpressインスタンスを指すようにweb.configを変更し、テンプレートで生成されたMDFを削除しました。私のWeb.Configには次のものがあります。

<add name="DefaultConnection" 
    connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Administration;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>

株式会員コードには、DBを初期化するための呼び出しがあります。

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

アプリケーションが起動すると、予想どおり、テーブルが管理データベースに作成されます。ユーザーを作成でき、それらは管理に入力されます。ロールテーブルにデータを入力し、コードを使用してユーザーのプロファイルにロールを追加し、それが実行されたことを確認できます。例えば:

Roles.GetRolesForUser("kristian"); // = string[] { "Administrator" }

しかし、次のような役割ベースの承認を使用しようとすると、次のようになります。

[Authorize(Roles = "Administrator")]

次の例外が発生します。

Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.

それは私にそれがまだMDFファイルを作成しようとしていると思わせる長い厄介なスタックトレースを与えます:

[SqlException(0x80131904):ユーザーインスタンスのプロセスの開始に失敗したため、SQLServerのユーザーインスタンスの生成に失敗しました。接続は閉じられます。]System.Data.SqlClient.SqlInternalConnection.OnError(SqlException例外、ブールブレーク接続、アクション1 wrapCloseInAction) +5295167 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +242 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1682 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +69 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +30 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +317 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +889 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +5309659 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions) +38 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1再試行、DbConnectionOptions userOptions、DbConnectionInternal&接続)+5311874 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection externalConnection、DbConnectionFactory connectionFactory 、TaskCompletionSource 1 retry, DbConnectionOptions userOptions) +143 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1再試行)+83 System.Data.SqlClient.SqlConnection.Open()+96 System.Web.Management.SqlServices.GetSqlConnection(String server、String user、String password、Boolean trusted、String connectionString)+76

[HttpException(0x80004005):SQLServerデータベースに接続できません。]System.Web.Management.SqlServices.GetSqlConnection(String server、String user、String password、Boolean trusted、String connectionString)+131System.Web.Management.SqlServices。 SetupApplicationServices(String server、String user、String password、Boolean trusted、String connectionString、String database、String dbFileName、SqlFeatures features、Boolean install)+89 System.Web.Management.SqlServices.Install(String database、String dbFileName、String connectionString) +27 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName、String dataDir、String connectionString)+386

この喜びの束の一番下にある行は、削除されたMDF('System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile')に関連していると思います。私はこれで正しいですか?または、テンプレートによって実装された承認が不完全ですか?

他の誰かがこれに対処したか、私の属性の使用が失敗する理由を知っている場合は、助けていただければ幸いです。

4

1 に答える 1

1

私はこれと同じ問題を抱えていました。SimpleMembershipを適切に初期化していないことに関連しているようです。それが使用されていることを確認するか[InitializeSimpleMembership]、直接電話してみてくださいDatabase.SetInitializer<UsersContext>(null);

于 2013-02-11T18:01:55.993 に答える