Login failed for user 'UserName'

Discussion in 'ASP.NET / ASP.NET Core' started by colorado, Jun 19, 2010.

  1. Hello People,

    Pls help, i'm getting this error Login failed for user 'UserName'. Its so strange because the connection string in web.config is correct. Also the username has access to the remote database, yet it gives this error.

    Any ideas?
     
  2. ...We can help, it is however very often rather tricky, so many variables, but let's try...
    Can you list your steps?
    i.e. Created the roles locally, used the Attach feature, etc.
    All the best,
    Mark
     
  3. Thanks Mark,

    1. Basically i uploaded the .bak of the database to the _database folder and then restored it.

    2. I added the 'UserName' as provided by discountasp to the database and assigned it the dbo role

    3. I updated the Connection string in web.config to:

    connectionString="Data Source=tcp:mssql03.discountasp.net;Initial Catalog=DB_226111_database;User ID=DB_226111_database_user;Password=password;Min Pool Size=5;Max Pool Size=90;Connect Timeout=60;". This worked until another issue arose.

    4. Initially i had no issues with referencing the database as i had declared the connection object in each page. After i realized that some connection was leaking due to unclosed connections, i decided to create a base class as stated below as have all pages reference it:

    --------------------------------------------------------------------
    Imports System.Data.SqlClient
    Imports System.Data
    Imports Microsoft.VisualBasic

    Public Class dbConn
    Inherits System.Web.UI.Page


    Public _sqlConn As New SqlConnection
    Public Sub New()

    Try
    _sqlConn = New SqlConnection(ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString)
    _sqlConn.Open()

    Catch ex As Exception
    Throw ex
    Finally
    _sqlConn.Close()
    End Try
    End Sub


    End Class
    ----------------------------------------------------------------------
    Thats where this error began. tried all sorts, still no show. Pls help !
     
  4. Hi,
    Some of that code seems like you aren't using Visual Studio in Web mode..are you?
    What did you use to code it?

    This gets a bit crazy but don't get frustrated.
    I'll check for your next post.
    All the best,
    Mark
     
  5. Yes i'm using Visual Studio in web mode.

    Are you asking this because of the 'Imports Microsoft.VisualBasic' portion ?
     
  6. ...Yeah, that part threw me off. ;-)
    I do use VB in VS but have not noticed it import VB for this sort of thing.
    Is this a login page that has code behind?
    Sorry if I'm being a bit dense tonight. ;-)
    (Have been on a mission these past few days to bury an Airman returning from Afgan.)
    All the best,
    Mark
     
  7. I see. Hope your task hasn't too stressful.

    The VB import was created when i was adding the 'vb' base class.

    its not a login function. Basically i have the base class and the database connection setup there as shown in the code i pasted previously. This base class inherits the 'Page' class, then in return all the pages inherit the 'base' class.

    When i publish and run it on my local webserver, i dont have any issues. But when i upload the compiled codes online thats when it displays the login error.

    Its so amazing cos some of the functions on the same page i.e tree view use the same base class connection and i see the content, while some other function i.e datalist are blank with the database login error showing up...
     
  8. ...I haven't done a tree view with data.
    Can't it be done with a dataset like say for example a detail or listview?
    VS makes that part so easy you don't have to code the conn parts anymore.
    If you want I'll play with that sort of code a bit.
    All the best,
    Mark

    PS - Thanks. We have one more honorable formal function for B. White tomorrow.
    He was a Senior Airman that got shot down in a HH-60G Pavehawk helicopter that crashed in southeastern Afghanistan.
     
  9. Hi Mark,

    Thanks for your help so far. I don't have issues with the tree view, as it works perfectly.

    What i need help on is on the error that shows up. Here is the scenario again

    1. I have a base class where i declared my connection object that also looks at my connection string in the web.config file.
    2. All my pages inherit from this base class. The base class further inherits the pages class. So thats the cycle for that area.
    3. On my local system i have no issues viewing the website, but on the remote site it throws up the error: Login failed for user 'DB_236111_database_user'
    4. I have added the database user to the dbo role in the database and the connection string is:

    <connectionStrings>
    <add name="DatabaseConnectionString" connectionString="Data Source=mssql08.discountasp.net;Initial Catalog=DB_236111_database;User ID=DB_236111_database_user;Password=password;Min Pool Size=5;Max Pool Size=90;Connect Timeout=60;"
    providerName="System.Data.SqlClient" />
    </connectionStrings>

    As I said, this user is already added to the database: DB_236111_database as dbo, so i cant understand why it is throwing up the error.

    Pls help !
     
  10. Hi,
    Mission is completed, I'm back at home, lets get this done. ;-)

    Email me your conn string and let me create a test page from here, see if it works.
    If it does I'll send you the code and you can fudge with it to get it working with that.
    Sound like a plan? [email protected]

    I'll do what I can, need a shower first of course. ;-)
    All the best,
    Mark
     
  11. Hi Mark,

    Glad to know u are back.

    --------------------------This is the base class i used

    Imports System.Data.SqlClient
    Imports System.Data
    Imports Microsoft.VisualBasic

    Public Class dbConn
    Inherits System.Web.UI.Page


    Public _sqlConn As New SqlConnection
    Public Sub New()

    Try
    _sqlConn = New SqlConnection(ConfigurationManager.ConnectionStrin gs("DatabaseConnectionString").ConnectionString)
    _sqlConn.Open()

    Catch ex As Exception
    Throw ex
    Finally
    _sqlConn.Close()
    End Try
    End Sub


    End Class


    ----------------This is the connection String in web.config

    connectionString="Data Source=tcp:mssql03.discountasp.net;Initial Catalog=DB_226111_database;User ID=DB_226111_database_user;Password=password;Min Pool Size=5;Max Pool Size=90;Connect Timeout=60;"

    -----------------On every page this is how i call up the database connection. This particular 'about us' page calls the stored procedure and passes the data to a datalist. It also inherits from the base class.

    Partial Class aboutus
    Inherits dbConn

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    Dim PageContent As String = Nothing

    Dim dt As New DataTable()
    Dim con As New SqlConnection(_sqlConn.ConnectionString)
    Dim sda As New SqlDataAdapter()
    Dim cmd As New SqlCommand("sp_Content_AboutUs")
    cmd.CommandType = CommandType.StoredProcedure
    cmd.Parameters.Add("@PageContent", SqlDbType.Text).Value = PageContent
    cmd.Connection = con
    Try
    con.Open()
    sda.SelectCommand = cmd
    sda.Fill(dt)
    DataList1.DataSource = dt
    DataList1.DataBind()
    Catch ex As Exception
    Response.Write(ex.Message)
    Finally
    con.Close()
    sda.Dispose()
    End Try

    End Sub
    End Class

    --------------------Pls help !
     
  12. ...I think you can use your ConnectionString there in that Sub without the Public Class.
    Unless I'm mistaken I've seen some bugs posted using a DataTable with a DataList datasource like that.
    Search the forums over at the ASP.NET site, you should be able to dig up something.
    http://forums.asp.net/
    All the best,
    Mark
     

Share This Page