デフォルトの「My ASP.NET Application」でアカウントを作成しようとすると、上記のエラーが発生します。Ms SQLServer 2008 および Visual Studio 2010 バージョンの新しいコピーを Windows 7 OS にインストールしました。ASP.net で DB 接続をテストするために、My ASP.NET アプリケーションを使用してアカウントを作成しようとしましたが、次のエラーの詳細が表示されました。asp.net開発は初めてです。したがって、このエラーを修正する方法が明確にわかりません。
- すべての SQL サービスが実行されています。
- MSSQLSERVER のすべてのプロトコルが有効になっています。
「/」アプリケーションでサーバー エラーが発生しました。SQL Server への接続を確立中に、ネットワーク関連またはインスタンス固有のエラーが発生しました。サーバーが見つからないか、アクセスできませんでした。インスタンス名が正しいこと、および SQL Server がリモート接続を許可するように構成されていることを確認してください。(プロバイダー: SQL ネットワーク インターフェイス、エラー: 26 - 指定されたサーバー/インスタンスの検索エラー) 説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。
SQLExpress データベース ファイルの自動作成エラー:
接続文字列は、アプリケーションの App_Data ディレクトリ内のデータベースの場所を使用して、ローカルの Sql Server Express インスタンスを指定します。プロバイダーは、データベースが存在しないと判断したため、アプリケーション サービス データベースを自動的に作成しようとしました。アプリケーション サービス データベースの存在を正常に確認し、アプリケーション サービス データベースを自動的に作成するには、次の構成要件が必要です。
アプリケーションが Windows 7 または Windows Server 2008R2 で実行されている場合、プロバイダー データベースの自動作成を有効にするには、特別な構成手順が必要です。追加情報は、http: //go.microsoft.com/fwlink/?LinkId=160102で入手できます。アプリケーションの App_Data ディレクトリがまだ存在しない場合、Web サーバー アカウントには、アプリケーションのディレクトリへの読み取りおよび書き込みアクセス権が必要です。App_Data ディレクトリがまだ存在しない場合、Web サーバー アカウントによって自動的に作成されるため、これが必要です。
アプリケーションの App_Data ディレクトリが既に存在する場合、Web サーバー アカウントには、アプリケーションの App_Data ディレクトリへの読み取りおよび書き込みアクセスのみが必要です。これが必要になるのは、アプリケーションの App_Data ディレクトリ内に Sql Server Express データベースが既に存在することを Web サーバー アカウントが検証しようとするためです。Web サーバー アカウントから App_Data ディレクトリへの読み取りアクセスを取り消すと、プロバイダーは Sql Server Express データベースが既に存在するかどうかを正しく判断できなくなります。これにより、プロバイダーが既存のデータベースの複製を作成しようとすると、エラーが発生します。新しいデータベースの作成時に Web サーバー アカウントの資格情報が使用されるため、書き込みアクセスが必要です。Sql Server Express がマシンにインストールされている必要があります。Web サーバー アカウントのプロセス ID には、ローカル ユーザー プロファイルが必要です。マシン アカウントとドメイン アカウントの両方のローカル ユーザー プロファイルを作成する方法の詳細については、readme ドキュメントを参照してください。
スタックトレース:
[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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5063578
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) +270
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) +5077239
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
[HttpException (0x80004005): Unable to connect to SQL Server database.]
System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +137
System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) +94
System.Web.Management.SqlServices.Install(String database, String dbFileName, String connectionString) +27
System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +395
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>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<membership>
<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="/" />
</providers>
</membership>
<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile>
<roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>