Unable to Auto-Create ASPNETDB.MDF - Visual Web De

2020-04-21 06:42发布

问题:

I Recently began learning ASP.net / SQL. I Installed Sql Server 2008R2 Express Edition; and Visual Web Designer 2008 Express Edition. I recently tried to create a login page and was unsuccessful; any help would be appreciated. I tried by taking the following steps:
-Create New WebSite
-Go to design view
-Drag "login status" into design view; Drag "Login" control onto design view as well;
-In Web.config I changed the authentication to "forms" (didnt add anything else)
-Run the page without debug / Type in any information in the login to have a "ASPNETDB.MDF" file automatically created into my "app_data" folder; and i receive the error below.

Note: Sql Server has "allow Remote connections" enabled, In configuration manager i enabled tcp/ip and "pipes" (these were measures i took after the fact that i couldnt get the DB auto created.) I Have tried "connecting databases" to my visual web designer program. Also worth noting that When connecting databases i use .\ or localhost\ no istance name because this is the only way V.W.Designer detects my databases.

The stack trace you cant see in the picture is as follow:

[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) +4849015 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4862333 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4863459 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +29 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +4865788 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117 System.Data.SqlClient.SqlConnection.Open() +122 System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) +82

[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) +25 System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) +395

回答1:

I Was able to get it working! Things worth mentioning / thinking about if your debugging the same issue.

When connecting to databases i would have to use Localhost\ As opposed to an instance. If you do as well and cannot connect properly and have the error listed above then install a named instance (install sql server and when you get to the Instance menu, dont use "default" use a named instance - i used SQLExpress) I also changed the fact that before i would use only "windows authentication" for logging on to my server and when i re-installed i allowed "Mixed" instead.

Those were the only changes i made that actually allowed my Database to be automatically created the way i needed it to.

also in web.config change the authentication section to "Forms" instead of "Window.

also be sure that your visual web developer has the correct SQL instance in visual web developer (i used 2008) go to - Tools -> options -> Click the show all settings box at the bottom left -> database tools -> Data connections -> SQL Server instance should have the Same name as the instance you installed prior.

These should handle the error 26 you get when trying to use a login page for the first time. Other helpful links were posted in this page: Creating .MDF With SQL 2008 EXPRESS/ Visual Web Developer 2008