Changing ASPNETDB.mdf to ubo.mdf

Last post 06-18-2008 5:12 AM by XiaoYong Dai – MSFT. 4 replies.

Sort Posts:

  • Changing ASPNETDB.mdf to ubo.mdf

    06-16-2008, 6:58 PM
    • Member
      37 point Member
    • jfeeney
    • Member since 04-07-2008, 12:16 PM
    • Posts 311

    I built the login program by fallling the Login Controls tutorial. I did not use the SecurityTutorial.mdf database name but with the standard ASPNETDB.mdf.

    Now I would need to change the name to ubo because I can't use the ASPNETDB name when I am taking into the hosted server.

    I had my program working. I have made the following changes

    I right clicked ASPNETDB (in App_Data) and renamed it to ubo.mdf

    web.config

    <connectionStrings>

    <add name="uboConnectionString"

    connectionString="DataSource=.\SQLEXPRESS;AttachDbFilename=C:\UBO\ubo\App_Data\ubo.MDF;Integrated Security=True;User Instance=True"

    providerName="System.Data.SqlClient"/>

    </connectionStrings>

    I am getting the following error message:

    Also because it is not working I added a Label and variable cString to my Login.aspx.cs

    protected void Login1_LoginError(object sender, EventArgs e)

    {

    string cString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionStrings"].ConnectionString;

    Label1.Text = cString;

    // Determine why the user could not login...

    myLogin.FailureText = "Your login attempt was not successful. Please try again.";

    // Does there exist a User account for this user?

    MembershipUser usrInfo = Membership.GetUser(myLogin.UserName);if (usrInfo != null)

    {

    // Is this user locked out?

    if (usrInfo.IsLockedOut)

    {

    myLogin.FailureText =
    "Your account has been locked out because of too many invalid login attempts. Please contact the administrator to have your account unlocked.";

    }

    else if (!usrInfo.IsApproved)

    {

    myLogin.FailureText =
    "Your account has not yet been approved. You cannot login until an administrator has approved your account.";

    }

    }

     I am getting the following error

    Object reference not set to an instance of an object.

    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.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 25:     protected void Login1_LoginError(object sender, EventArgs e)
    Line 26:     {
    Line 27:         string cString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionStrings"].ConnectionString;
    Line 28:         Label1.Text = cString;
    Line 29:         // Determine why the user could not login...


    Source File: c:\UBO\ubo\Login.aspx.cs    Line: 27

    ???? Why will the connection string be null ????

  • Re: Changing ASPNETDB.mdf to ubo.mdf

    06-16-2008, 8:04 PM
    Answer
    • All-Star
      17,168 point All-Star
    • guru_sarkar
    • Member since 08-30-2007, 8:00 PM
    • Posts 2,608

     

    string cString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionStrings"].ConnectionString;
     replace connectionStrings by uboConnectionString
  • Re: Changing ASPNETDB.mdf to ubo.mdf

    06-16-2008, 8:24 PM
    • Member
      37 point Member
    • jfeeney
    • Member since 04-07-2008, 12:16 PM
    • Posts 311

    I actually did get the connection string to display by using these code lines

    ConnectionStringSettings settings;settings = System.Configuration.ConfigurationManager.ConnectionStrings["uboConnectionString"];

    Label1.Text = settings.ConnectionString;

    ALSO

    I now have my website running on the remote server. However, it does not run on my test site. The only thing that I change between them is the connection string section of web.config.

    here is my connectionstring for the test site

    <connectionStrings>

    <add name="uboConnectionString"

    connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\UBO\ubo\App_Data\ubo.MDF;Integrated Security=True;User Instance=True"

    providerName="System.Data.SqlClient"/>

    </connectionStrings>

    Does any see what I have doing wrong here.....or if nothing....can some give me an idea of a simple way to test if the database can be found.

    If I go into Database Explorer and right-click on ubo.mdf and hit Modify Connection I window comes up. At the bottom it says "Test Connection" when I hit that it says "Test Connection Succeeded".

  • Re: Changing ASPNETDB.mdf to ubo.mdf

    06-16-2008, 9:04 PM
    • Member
      37 point Member
    • jfeeney
    • Member since 04-07-2008, 12:16 PM
    • Posts 311

    When I tried using this connectionstring I got the following error message

    <connectionStrings>

    <add name ="uboConnectionString"

    connectionString="Data Source=.\SQLEXPRESS;

    Initial Catalog=ubo.MDF;

    Integrated Security=True;

    User Instance=True"

    providerName="System.Data.SqlClient"/>

    </connectionStrings>

    Server Error in '/ubo' Application.

    Cannot open database "ubo.MDF" requested by the login. The login failed.
    Login failed for user 'John-PC\John'.

    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.

    Exception Details: System.Data.SqlClient.SqlException: Cannot open database "ubo.MDF" requested by the login. The login failed.
    Login failed for user 'John-PC\John'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [SqlException (0x80131904): Cannot open database "ubo.MDF" requested by the login. The login failed.
    Login failed for user 'John-PC\John'.]
       System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +800131
       System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +186
       System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1932
       System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +33
       System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +172
       System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +381
       System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +181
       System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +173
       System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +357
       System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +30
       System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +424
       System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
       System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +494
       System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +82
       System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105
       System.Data.SqlClient.SqlConnection.Open() +111
       System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +84
       System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +197
       System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username, Boolean updateLastLoginActivityDate, Int32& status, String& password, Int32& passwordFormat, String& passwordSalt, Int32& failedPasswordAttemptCount, Int32& failedPasswordAnswerAttemptCount, Boolean& isApproved, DateTime& lastLoginDate, DateTime& lastActivityDate) +1121
       System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved, String& salt, Int32& passwordFormat) +105
       System.Web.Security.SqlMembershipProvider.CheckPassword(String username, String password, Boolean updateLastLoginActivityDate, Boolean failIfNotApproved) +42
       System.Web.Security.SqlMembershipProvider.ValidateUser(String username, String password) +83
       System.Web.UI.WebControls.Login.OnAuthenticate(AuthenticateEventArgs e) +160
       System.Web.UI.WebControls.Login.AttemptLogin() +105
       System.Web.UI.WebControls.Login.OnBubbleEvent(Object source, EventArgs e) +99
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
       System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
    

  • Re: Changing ASPNETDB.mdf to ubo.mdf

    06-18-2008, 5:12 AM
    Answer

    Hi

    It seems that ASP.NET failed to connect to Sql server using a trusted connection (windows authentication mode).

    You can add 'John-PC\John' account to the SQL logins by using SQL Server Management Studio->connect to the SQL instance->expand Security->Logins->add New Windows Login

    Hope it helps

    Best Regards
    XiaoYong Dai
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (5 items)