Help -- SQLConnection Problem

Discussion in 'ASP .Net' started by Michael D Murphy, Sep 3, 2005.

  1. Hi,
    I continually have problems with SQLConnections. Once I fix the one that I
    am having problems with I move on. I would rather have more confidence. I
    must be not understanding something or another. If I drag a SQLConnection to
    the form and configure it and then drag a SQLDataAdapter to the form and
    configure that, then right click on the SQLAdapter and click on Preview
    Data, I always get the data. But if I use that exact SQLConnection object or
    copy all the properties of that SQLConnection object to a new SQLConnection
    object, and try to connect I get errors. Why would it work one way and not
    the other. If you could point me to a SQLConnection primer or other tutorial
    that will finally get me past these problems, I would appreciate it.
    Thanks for your time,
    Michael
    954-452-1047
     
    Michael D Murphy, Sep 3, 2005
    #1
    1. Advertising

  2. Michael D Murphy

    Jordan Guest

    I see no one has responded for over 6 hours - so here' my 2 cents-worth:

    Don't use the SQLConnection and SQLDataAdapter objects from the toolbox.
    Seriously. Instead, code it by hand. Nobody I've ever seen or heard of
    actually uses those objects from the toolbox for any non trivial ASP.NET
    application development.

    Why?

    1 -- Because of the exact sort of problem you are having - and many others.
    The problem is that you don't really know what's going on behind the scenes
    and why things seem to break so easily with these objects. The only place I
    think they're used is in training courses and intro-level books where
    they're trying to show you how "easy" connectivity is. The problem is that
    it is really that easy - but only if you hand-code it all (IMHO). It's far
    more difficult if you use these objects from the toolbox. The only time they
    really shine is during a tutorial or class where you are supposed to follow
    some exact steps. You follow them - and Bingo! it all works - very
    impressive! But now you need to do some real work -and you're screwed
    because they hide so much from you.

    2 -- Economics: The amount of time you spend screwing around with these
    "training wheels" could have been spent learning how to hand-code things
    (which really is not a difficult thing to do; just a few lines of code and
    you're in business). Debugging a few lines of code is far easier than trying
    to figure out why an extra layer of indirection is - well, indirecting you.

    I'm not being cynical here - just realistic. The bottom line is that you're
    going to spend a certain amount of time getting your connectivity going -
    either by learning how to write code to do it or by screwing around with
    these wrappers. Your choice. I suspect that nobody is helping you with these
    wrappers because they don't use or understand them... just a hunch...

    -HTH


    "Michael D Murphy" <> wrote in message
    news:...
    > Hi,
    > I continually have problems with SQLConnections. Once I fix the one that I
    > am having problems with I move on. I would rather have more confidence. I
    > must be not understanding something or another. If I drag a SQLConnection
    > to the form and configure it and then drag a SQLDataAdapter to the form
    > and configure that, then right click on the SQLAdapter and click on
    > Preview Data, I always get the data. But if I use that exact SQLConnection
    > object or copy all the properties of that SQLConnection object to a new
    > SQLConnection object, and try to connect I get errors. Why would it work
    > one way and not the other. If you could point me to a SQLConnection primer
    > or other tutorial that will finally get me past these problems, I would
    > appreciate it.
    > Thanks for your time,
    > Michael
    > 954-452-1047
    >
     
    Jordan, Sep 4, 2005
    #2
    1. Advertising

  3. Michael D Murphy

    Jordan Guest

    A primer to help you really understand what's going on with connectivity:

    "Microsoft ADO.NET" by David Sceppa - Microsoft Press

    It's a thick book - but totally understandable to the beginner - and you
    don't need to read the whole thing to get going.



    "Michael D Murphy" <> wrote in message
    news:...
    > Hi,
    > I continually have problems with SQLConnections. Once I fix the one that I
    > am having problems with I move on. I would rather have more confidence. I
    > must be not understanding something or another. If I drag a SQLConnection
    > to the form and configure it and then drag a SQLDataAdapter to the form
    > and configure that, then right click on the SQLAdapter and click on
    > Preview Data, I always get the data. But if I use that exact SQLConnection
    > object or copy all the properties of that SQLConnection object to a new
    > SQLConnection object, and try to connect I get errors. Why would it work
    > one way and not the other. If you could point me to a SQLConnection primer
    > or other tutorial that will finally get me past these problems, I would
    > appreciate it.
    > Thanks for your time,
    > Michael
    > 954-452-1047
    >
     
    Jordan, Sep 4, 2005
    #3
  4. Michael,



    This will help you setting up your connection string.

    http://www.connectionstrings.com/



    What do you mean by "copy all the properties of that SQLConnection object to
    a new SQLConnection"? Do you really mean all? Do you now have two
    SQLConnection Objects having the same name? If you could provide us with the
    error message you get it would me much easier to find a solution to your
    problem.

    Basically I agree to what Jordan said. What I usually do is dragging a
    SQLConnection of my form, copy the connection string, delete the
    SQLConnection again and then create the SQLConnection in code behind using
    the connection string I copied (I always forget about
    theconnectionstrings.com).



    You should also have a look at the msdn reference which comes with some nice
    examples:

    http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp





    Does this help?



    Daniel Walzenbach





    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:...
    > Hi,
    > I continually have problems with SQLConnections. Once I fix the one that I
    > am having problems with I move on. I would rather have more confidence. I
    > must be not understanding something or another. If I drag a SQLConnection
    > to the form and configure it and then drag a SQLDataAdapter to the form
    > and configure that, then right click on the SQLAdapter and click on
    > Preview Data, I always get the data. But if I use that exact SQLConnection
    > object or copy all the properties of that SQLConnection object to a new
    > SQLConnection object, and try to connect I get errors. Why would it work
    > one way and not the other. If you could point me to a SQLConnection primer
    > or other tutorial that will finally get me past these problems, I would
    > appreciate it.
    > Thanks for your time,
    > Michael
    > 954-452-1047
    >
     
    Daniel Walzenbach, Sep 4, 2005
    #4
  5. Thanks so much for your replies!
    I have done quite a lot of work in ASP.Net and am quite familiar with it.
    But for some reason, I just can't understand why some connections are so
    simply implemented and others are so unmanageable. I normally code the
    SQLConnection but when I run into connection problems I revert back to the
    drag and drop the SQLConnection Object from the toolbox onto the page. I
    then go through the process of creating a SQLDataAdapter and configure it
    until I can actually see the data in the 'Preview Data' window. At that
    point I figure the SQLConnection object is configured correctly so now I go
    into the code and enter something like this:

    Dim MyConnectionString as string
    MyConnectionString =
    Dim MySQLConnection as New SQLConnection(MyConnectionString)
    MySQLConnection.Open()

    And when I rebuild the project and step through the code it bombs on the
    Open!
    The only thing I could check was Server,GetLastError.Message---which is set
    to Object set to Nothing.

    How do I track down the exact problem here in both situations:
    Debugging on my local machine with data on that machine
    Debugging if the database is on a remote machine and I have no way to access
    the program and data outside the host's firewall--some kind of print
    statements??.

    Thanks again for your time.
    Michael


    "Daniel Walzenbach" <> wrote in message
    news:OYo36$...
    > Michael,
    >
    >
    >
    > This will help you setting up your connection string.
    >
    > http://www.connectionstrings.com/
    >
    >
    >
    > What do you mean by "copy all the properties of that SQLConnection object
    > to a new SQLConnection"? Do you really mean all? Do you now have two
    > SQLConnection Objects having the same name? If you could provide us with
    > the error message you get it would me much easier to find a solution to
    > your problem.
    >
    > Basically I agree to what Jordan said. What I usually do is dragging a
    > SQLConnection of my form, copy the connection string, delete the
    > SQLConnection again and then create the SQLConnection in code behind using
    > the connection string I copied (I always forget about
    > theconnectionstrings.com).
    >
    >
    >
    > You should also have a look at the msdn reference which comes with some
    > nice examples:
    >
    > http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >
    >
    >
    >
    >
    > Does this help?
    >
    >
    >
    > Daniel Walzenbach
    >
    >
    >
    >
    >
    > "Michael D Murphy" <> schrieb im Newsbeitrag
    > news:...
    >> Hi,
    >> I continually have problems with SQLConnections. Once I fix the one that
    >> I am having problems with I move on. I would rather have more confidence.
    >> I must be not understanding something or another. If I drag a
    >> SQLConnection to the form and configure it and then drag a SQLDataAdapter
    >> to the form and configure that, then right click on the SQLAdapter and
    >> click on Preview Data, I always get the data. But if I use that exact
    >> SQLConnection object or copy all the properties of that SQLConnection
    >> object to a new SQLConnection object, and try to connect I get errors.
    >> Why would it work one way and not the other. If you could point me to a
    >> SQLConnection primer or other tutorial that will finally get me past
    >> these problems, I would appreciate it.
    >> Thanks for your time,
    >> Michael
    >> 954-452-1047
    >>

    >
    >
     
    Michael D Murphy, Sep 4, 2005
    #5
  6. Hi,
    I just went and tried to do the same thing with Northwind and get the
    following message:
    Cannot open database requested in login 'Northwind'. Login fails. Login
    failed for user 'MDMDELL1\ASPNET'.
    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
    requested in login 'Northwind'. Login fails. Login failed for user
    'MDMDELL1\ASPNET'.

    Source Error:


    Line 125: Session.Add("mySqlConString", mySqlConString)
    Line 126: pub_ABCEF_SQLCon = New SqlConnection(mySqlConString)
    Line 127: pub_ABCEF_SQLCon.Open()
    Line 128: Dim MySqlCommand As SqlCommand = New SqlCommand
    Line 129: With MySqlCommand


    But in the data adapter, it obviously logs in just fine because I can
    preview the data.
    Any thoughts?
    Thanks,
    Michael
     
    Michael D Murphy, Sep 4, 2005
    #6
  7. I corrected the problem with the SQLConnection.Open() -- I had to add the
    user ASPNET to the database. And that is another thing that bothers me--why
    didn't that error occur when I was previewing the data in the data adapter??
    My outstanding problem at this point is how do I track down errors
    (connection errors in this case) that occur on a page when the only tool I
    have is FTPing my files to the remote server.

    Thanks,
    Michael


    "Daniel Walzenbach" <> wrote in message
    news:OYo36$...
    > Michael,
    >
    >
    >
    > This will help you setting up your connection string.
    >
    > http://www.connectionstrings.com/
    >
    >
    >
    > What do you mean by "copy all the properties of that SQLConnection object
    > to a new SQLConnection"? Do you really mean all? Do you now have two
    > SQLConnection Objects having the same name? If you could provide us with
    > the error message you get it would me much easier to find a solution to
    > your problem.
    >
    > Basically I agree to what Jordan said. What I usually do is dragging a
    > SQLConnection of my form, copy the connection string, delete the
    > SQLConnection again and then create the SQLConnection in code behind using
    > the connection string I copied (I always forget about
    > theconnectionstrings.com).
    >
    >
    >
    > You should also have a look at the msdn reference which comes with some
    > nice examples:
    >
    > http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >
    >
    >
    >
    >
    > Does this help?
    >
    >
    >
    > Daniel Walzenbach
    >
    >
    >
    >
    >
    > "Michael D Murphy" <> schrieb im Newsbeitrag
    > news:...
    >> Hi,
    >> I continually have problems with SQLConnections. Once I fix the one that
    >> I am having problems with I move on. I would rather have more confidence.
    >> I must be not understanding something or another. If I drag a
    >> SQLConnection to the form and configure it and then drag a SQLDataAdapter
    >> to the form and configure that, then right click on the SQLAdapter and
    >> click on Preview Data, I always get the data. But if I use that exact
    >> SQLConnection object or copy all the properties of that SQLConnection
    >> object to a new SQLConnection object, and try to connect I get errors.
    >> Why would it work one way and not the other. If you could point me to a
    >> SQLConnection primer or other tutorial that will finally get me past
    >> these problems, I would appreciate it.
    >> Thanks for your time,
    >> Michael
    >> 954-452-1047
    >>

    >
    >
     
    Michael D Murphy, Sep 4, 2005
    #7
  8. Michael D Murphy

    Jordan Guest

    Has the user - 'MDMDELL1\ASPNET' - been added to your SQL Server as a valid
    login to both (1) the server and (2) the database? If not, give that a shot.
    To verify, log in via QueryAnalyzer using that specific login.

    Perhaps the SQLConnection login from the toolbox is attempting to connect AS
    some other user (perhaps the currently logged in [to Windows] user - you -
    and not as the MDMDELL1\ASPNet user.

    -HTH


    "Michael D Murphy" <> wrote in message
    news:%...
    > Hi,
    > I just went and tried to do the same thing with Northwind and get the
    > following message:
    > Cannot open database requested in login 'Northwind'. Login fails. Login
    > failed for user 'MDMDELL1\ASPNET'.
    > 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 requested in login 'Northwind'. Login fails. Login failed for
    > user 'MDMDELL1\ASPNET'.
    >
    > Source Error:
    >
    >
    > Line 125: Session.Add("mySqlConString", mySqlConString)
    > Line 126: pub_ABCEF_SQLCon = New SqlConnection(mySqlConString)
    > Line 127: pub_ABCEF_SQLCon.Open()
    > Line 128: Dim MySqlCommand As SqlCommand = New SqlCommand
    > Line 129: With MySqlCommand
    >
    >
    > But in the data adapter, it obviously logs in just fine because I can
    > preview the data.
    > Any thoughts?
    > Thanks,
    > Michael
    >
     
    Jordan, Sep 4, 2005
    #8
  9. Michael D Murphy

    Jordan Guest

    <<how do I track down errors (connection errors in this case) that occur on
    a page >>

    The exception object contains a .StackTrace property. This will tell you the
    specific line of code that choked. This, along with the .Message property of
    the exception object will tell you what went wrong and on which line of code
    the problem occurred.

    Note that in order to get the correct stack trace information, you'll have
    to be sure to copy the .pdb file along with the .dll file. The .pdb file
    contains the debugging information that will give you the stack trace/line
    number info. Whenever you compile a new dll, you'll get a new .pdb file.
    Always copy the current .pdb file with the .dll.

    Also, remember that exceptions are of different types. So, the SQLException
    object will have different properties available to help you determine what
    went wrong (e.g., name of the stored procedrue that choked, and the line
    number at which it choked). Your central error logger should differentiate
    between the types of Exceptions beign logged so it can log
    exception-type-specific property values.

    You can write a generic exception logging routine that centralizes this
    work - then call it in the catch blocks of your application.

    -HTH



    "Michael D Murphy" <> wrote in message
    news:ObT$...
    >I corrected the problem with the SQLConnection.Open() -- I had to add the
    >user ASPNET to the database. And that is another thing that bothers me--why
    >didn't that error occur when I was previewing the data in the data
    >adapter??
    > My outstanding problem at this point is how do I track down errors
    > (connection errors in this case) that occur on a page when the only tool I
    > have is FTPing my files to the remote server.
    >
    > Thanks,
    > Michael
    >
    >
    > "Daniel Walzenbach" <> wrote in message
    > news:OYo36$...
    >> Michael,
    >>
    >>
    >>
    >> This will help you setting up your connection string.
    >>
    >> http://www.connectionstrings.com/
    >>
    >>
    >>
    >> What do you mean by "copy all the properties of that SQLConnection object
    >> to a new SQLConnection"? Do you really mean all? Do you now have two
    >> SQLConnection Objects having the same name? If you could provide us with
    >> the error message you get it would me much easier to find a solution to
    >> your problem.
    >>
    >> Basically I agree to what Jordan said. What I usually do is dragging a
    >> SQLConnection of my form, copy the connection string, delete the
    >> SQLConnection again and then create the SQLConnection in code behind
    >> using the connection string I copied (I always forget about
    >> theconnectionstrings.com).
    >>
    >>
    >>
    >> You should also have a look at the msdn reference which comes with some
    >> nice examples:
    >>
    >> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>
    >>
    >>
    >>
    >>
    >> Does this help?
    >>
    >>
    >>
    >> Daniel Walzenbach
    >>
    >>
    >>
    >>
    >>
    >> "Michael D Murphy" <> schrieb im
    >> Newsbeitrag news:...
    >>> Hi,
    >>> I continually have problems with SQLConnections. Once I fix the one that
    >>> I am having problems with I move on. I would rather have more
    >>> confidence. I must be not understanding something or another. If I drag
    >>> a SQLConnection to the form and configure it and then drag a
    >>> SQLDataAdapter to the form and configure that, then right click on the
    >>> SQLAdapter and click on Preview Data, I always get the data. But if I
    >>> use that exact SQLConnection object or copy all the properties of that
    >>> SQLConnection object to a new SQLConnection object, and try to connect I
    >>> get errors. Why would it work one way and not the other. If you could
    >>> point me to a SQLConnection primer or other tutorial that will finally
    >>> get me past these problems, I would appreciate it.
    >>> Thanks for your time,
    >>> Michael
    >>> 954-452-1047
    >>>

    >>
    >>

    >
    >
     
    Jordan, Sep 4, 2005
    #9
  10. Michael,



    to make things more clear to you I'd suggest the following:



    1.) open query analyser and change to the database you are interested in.
    Execute the following statement:



    select DB_ID();



    remember the result.



    2.) open SQL Server Profiler and create a new trace (File -> New -> Trace)

    3.) open the Tab "Events" and remove everything except

    Stored Procedures, PRC: Completed,

    TSQL, SQL:BatchCompleted



    4.) open the Tab "Filters" and set DatabaseID equals (the Number you
    selected in step 1)



    5.) Preview the DataAdapter and see in Profiler which account is used





    What you now will see is the following:

    If you use the preview function your local user will be used.

    If you step through the code you'll see that the user defined in the
    connection string will be used...







    This is a little example you might use:



    ' **********************************

    ' ** SqlConnection

    ' **********************************



    ' create the connection

    Dim mySQLConnection As New System.Data.SqlClient.SqlConnection



    Try

    ' assign the ConnectionString

    mySQLConnection.ConnectionString = "Initial Catalog=Northwind;Data
    Source=localhost;User ID=NorthwindUser;Password=xxxxxx;Packet Size=4096;"



    ' open the connection

    mySQLConnection.Open()

    Catch ex As Exception

    ' write errors to the page

    Response.Write(ex.Message)



    End Try





    ' **********************************

    ' ** SqlCommand

    ' **********************************



    ' create a SQLCommand

    Dim mySQLCommand As New System.Data.SqlClient.SqlCommand



    ' assign the Connection to the Command

    mySQLCommand.Connection = mySQLConnection



    ' assign the SelectCommand

    mySQLCommand.CommandText = "SELECT [CustomerID], [CompanyName] FROM
    [Northwind].[dbo].[Customers]"



    ' assign the CommandType

    mySQLCommand.CommandType = CommandType.Text





    ' **********************************

    ' ** SqlDataAdapter

    ' **********************************



    ' create a SqlDataAdapter

    Dim mySQLDataAdapter As New System.Data.SqlClient.SqlDataAdapter



    ' assign the SqlCommand to the SqlDataAdapter

    mySQLDataAdapter.SelectCommand = mySQLCommand



    ' assign TableMapping

    mySQLDataAdapter.TableMappings.Add("Table", "Customers")





    ' **********************************

    ' ** DataSet

    ' **********************************



    ' create a DataSet

    Dim myDataSet As New System.Data.DataSet



    Try

    ' fill the DataSet

    mySQLDataAdapter.Fill(myDataSet)



    Catch ex As Exception

    ' write errors to the page

    Response.Write(ex.Message)



    End Try




    Regards

    Daniel Walzenbach


    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:ObT$...
    >I corrected the problem with the SQLConnection.Open() -- I had to add the
    >user ASPNET to the database. And that is another thing that bothers me--why
    >didn't that error occur when I was previewing the data in the data
    >adapter??
    > My outstanding problem at this point is how do I track down errors
    > (connection errors in this case) that occur on a page when the only tool I
    > have is FTPing my files to the remote server.
    >
    > Thanks,
    > Michael
    >
    >
    > "Daniel Walzenbach" <> wrote in message
    > news:OYo36$...
    >> Michael,
    >>
    >>
    >>
    >> This will help you setting up your connection string.
    >>
    >> http://www.connectionstrings.com/
    >>
    >>
    >>
    >> What do you mean by "copy all the properties of that SQLConnection object
    >> to a new SQLConnection"? Do you really mean all? Do you now have two
    >> SQLConnection Objects having the same name? If you could provide us with
    >> the error message you get it would me much easier to find a solution to
    >> your problem.
    >>
    >> Basically I agree to what Jordan said. What I usually do is dragging a
    >> SQLConnection of my form, copy the connection string, delete the
    >> SQLConnection again and then create the SQLConnection in code behind
    >> using the connection string I copied (I always forget about
    >> theconnectionstrings.com).
    >>
    >>
    >>
    >> You should also have a look at the msdn reference which comes with some
    >> nice examples:
    >>
    >> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>
    >>
    >>
    >>
    >>
    >> Does this help?
    >>
    >>
    >>
    >> Daniel Walzenbach
    >>
    >>
    >>
    >>
    >>
    >> "Michael D Murphy" <> schrieb im
    >> Newsbeitrag news:...
    >>> Hi,
    >>> I continually have problems with SQLConnections. Once I fix the one that
    >>> I am having problems with I move on. I would rather have more
    >>> confidence. I must be not understanding something or another. If I drag
    >>> a SQLConnection to the form and configure it and then drag a
    >>> SQLDataAdapter to the form and configure that, then right click on the
    >>> SQLAdapter and click on Preview Data, I always get the data. But if I
    >>> use that exact SQLConnection object or copy all the properties of that
    >>> SQLConnection object to a new SQLConnection object, and try to connect I
    >>> get errors. Why would it work one way and not the other. If you could
    >>> point me to a SQLConnection primer or other tutorial that will finally
    >>> get me past these problems, I would appreciate it.
    >>> Thanks for your time,
    >>> Michael
    >>> 954-452-1047
    >>>

    >>
    >>

    >
    >
     
    Daniel Walzenbach, Sep 4, 2005
    #10
  11. Thanks for your time Daniel,
    I will try all of what you suggest. Also, do you have a step by step
    approach to modifying the web.config and custom errors page so I can the
    most out of debugging when I cannot do it on my own machine? I have read
    something about CustomErrors tags in the web.config and get the messages
    when the exception arises, but I have not yet found a tutorial on how to set
    it all up. What I would like to do is have everything in place so when a
    problem arises I just go into the Web.config and change the value of
    CustomErrors and take a look at the output and make the needed changes.
    Thanks,
    Michael
     
    Michael D Murphy, Sep 4, 2005
    #11
  12. Michael,

    you are welcome! Have a look at this article:

    Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/elmah.asp

    This should be exaclty what you are looking for...


    Regarding the customError Page ->
    http://www.c-sharpcorner.com/Code/2005/July/ASP.NETCustomError.asp

    Remember that you should NOT display any error information on your
    customError Page as this might help somebody to attack your page (using the
    information the error provides...)

    Tell me if this helps!

    Daniel Walzenbach


    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:OXz%...
    > Thanks for your time Daniel,
    > I will try all of what you suggest. Also, do you have a step by step
    > approach to modifying the web.config and custom errors page so I can the
    > most out of debugging when I cannot do it on my own machine? I have read
    > something about CustomErrors tags in the web.config and get the messages
    > when the exception arises, but I have not yet found a tutorial on how to
    > set it all up. What I would like to do is have everything in place so when
    > a problem arises I just go into the Web.config and change the value of
    > CustomErrors and take a look at the output and make the needed changes.
    > Thanks,
    > Michael
    >
    >
     
    Daniel Walzenbach, Sep 4, 2005
    #12
  13. Daniel,
    Thanks loads for spending some of your weekend helping me.
    If you're ever coming to the Fort Lauderdale, Florida area, shoot me an
    email and we grab a beer or something!
    I'll let you know how things went.
    Michael

    "Daniel Walzenbach" <> wrote in message
    news:...
    > Michael,
    >
    > you are welcome! Have a look at this article:
    >
    > Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
    > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/elmah.asp
    >
    > This should be exaclty what you are looking for...
    >
    >
    > Regarding the customError Page ->
    > http://www.c-sharpcorner.com/Code/2005/July/ASP.NETCustomError.asp
    >
    > Remember that you should NOT display any error information on your
    > customError Page as this might help somebody to attack your page (using
    > the information the error provides...)
    >
    > Tell me if this helps!
    >
    > Daniel Walzenbach
    >
    >
    > "Michael D Murphy" <> schrieb im Newsbeitrag
    > news:OXz%...
    >> Thanks for your time Daniel,
    >> I will try all of what you suggest. Also, do you have a step by step
    >> approach to modifying the web.config and custom errors page so I can the
    >> most out of debugging when I cannot do it on my own machine? I have read
    >> something about CustomErrors tags in the web.config and get the messages
    >> when the exception arises, but I have not yet found a tutorial on how to
    >> set it all up. What I would like to do is have everything in place so
    >> when a problem arises I just go into the Web.config and change the value
    >> of CustomErrors and take a look at the output and make the needed
    >> changes.
    >> Thanks,
    >> Michael
    >>
    >>

    >
    >
     
    Michael D Murphy, Sep 4, 2005
    #13
  14. Thank you Michael! Glad if I could help!

    If I'll ever be around FL I'll write you ;-)

    Good luck!

    Daniel Walzenbach


    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:...
    > Daniel,
    > Thanks loads for spending some of your weekend helping me.
    > If you're ever coming to the Fort Lauderdale, Florida area, shoot me an
    > email and we grab a beer or something!
    > I'll let you know how things went.
    > Michael
    >
    > "Daniel Walzenbach" <> wrote in message
    > news:...
    >> Michael,
    >>
    >> you are welcome! Have a look at this article:
    >>
    >> Using HTTP Modules and Handlers to Create Pluggable ASP.NET Components
    >> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/elmah.asp
    >>
    >> This should be exaclty what you are looking for...
    >>
    >>
    >> Regarding the customError Page ->
    >> http://www.c-sharpcorner.com/Code/2005/July/ASP.NETCustomError.asp
    >>
    >> Remember that you should NOT display any error information on your
    >> customError Page as this might help somebody to attack your page (using
    >> the information the error provides...)
    >>
    >> Tell me if this helps!
    >>
    >> Daniel Walzenbach
    >>
    >>
    >> "Michael D Murphy" <> schrieb im
    >> Newsbeitrag news:OXz%...
    >>> Thanks for your time Daniel,
    >>> I will try all of what you suggest. Also, do you have a step by step
    >>> approach to modifying the web.config and custom errors page so I can the
    >>> most out of debugging when I cannot do it on my own machine? I have read
    >>> something about CustomErrors tags in the web.config and get the messages
    >>> when the exception arises, but I have not yet found a tutorial on how to
    >>> set it all up. What I would like to do is have everything in place so
    >>> when a problem arises I just go into the Web.config and change the value
    >>> of CustomErrors and take a look at the output and make the needed
    >>> changes.
    >>> Thanks,
    >>> Michael
    >>>
    >>>

    >>
    >>

    >
    >
     
    Daniel Walzenbach, Sep 4, 2005
    #14
  15. Hi Daniel
    I did what you suggested and noticed that the preview data used my windows
    account to access the data and the code version of the access used ASPNET.
    Kind of interesting! Also, this opens up some curiosities to begin using
    some of these tools--THANKS!
    If you can think of a webcast or tutorial that helps best use the tools,
    that would be great!
    In the mean time I will review the links that you have suggested.
    Thanks Again,
    Michael
    "Daniel Walzenbach" <> wrote in message
    news:OxP0$...
    > Michael,
    >
    >
    >
    > to make things more clear to you I'd suggest the following:
    >
    >
    >
    > 1.) open query analyser and change to the database you are interested in.
    > Execute the following statement:
    >
    >
    >
    > select DB_ID();
    >
    >
    >
    > remember the result.
    >
    >
    >
    > 2.) open SQL Server Profiler and create a new trace (File -> New -> Trace)
    >
    > 3.) open the Tab "Events" and remove everything except
    >
    > Stored Procedures, PRC: Completed,
    >
    > TSQL, SQL:BatchCompleted
    >
    >
    >
    > 4.) open the Tab "Filters" and set DatabaseID equals (the Number you
    > selected in step 1)
    >
    >
    >
    > 5.) Preview the DataAdapter and see in Profiler which account is used
    >
    >
    >
    >
    >
    > What you now will see is the following:
    >
    > If you use the preview function your local user will be used.
    >
    > If you step through the code you'll see that the user defined in the
    > connection string will be used...
    >
    >
    >
    >
    >
    >
    >
    > This is a little example you might use:
    >
    >
    >
    > ' **********************************
    >
    > ' ** SqlConnection
    >
    > ' **********************************
    >
    >
    >
    > ' create the connection
    >
    > Dim mySQLConnection As New System.Data.SqlClient.SqlConnection
    >
    >
    >
    > Try
    >
    > ' assign the ConnectionString
    >
    > mySQLConnection.ConnectionString = "Initial Catalog=Northwind;Data
    > Source=localhost;User ID=NorthwindUser;Password=xxxxxx;Packet Size=4096;"
    >
    >
    >
    > ' open the connection
    >
    > mySQLConnection.Open()
    >
    > Catch ex As Exception
    >
    > ' write errors to the page
    >
    > Response.Write(ex.Message)
    >
    >
    >
    > End Try
    >
    >
    >
    >
    >
    > ' **********************************
    >
    > ' ** SqlCommand
    >
    > ' **********************************
    >
    >
    >
    > ' create a SQLCommand
    >
    > Dim mySQLCommand As New System.Data.SqlClient.SqlCommand
    >
    >
    >
    > ' assign the Connection to the Command
    >
    > mySQLCommand.Connection = mySQLConnection
    >
    >
    >
    > ' assign the SelectCommand
    >
    > mySQLCommand.CommandText = "SELECT [CustomerID], [CompanyName] FROM
    > [Northwind].[dbo].[Customers]"
    >
    >
    >
    > ' assign the CommandType
    >
    > mySQLCommand.CommandType = CommandType.Text
    >
    >
    >
    >
    >
    > ' **********************************
    >
    > ' ** SqlDataAdapter
    >
    > ' **********************************
    >
    >
    >
    > ' create a SqlDataAdapter
    >
    > Dim mySQLDataAdapter As New System.Data.SqlClient.SqlDataAdapter
    >
    >
    >
    > ' assign the SqlCommand to the SqlDataAdapter
    >
    > mySQLDataAdapter.SelectCommand = mySQLCommand
    >
    >
    >
    > ' assign TableMapping
    >
    > mySQLDataAdapter.TableMappings.Add("Table", "Customers")
    >
    >
    >
    >
    >
    > ' **********************************
    >
    > ' ** DataSet
    >
    > ' **********************************
    >
    >
    >
    > ' create a DataSet
    >
    > Dim myDataSet As New System.Data.DataSet
    >
    >
    >
    > Try
    >
    > ' fill the DataSet
    >
    > mySQLDataAdapter.Fill(myDataSet)
    >
    >
    >
    > Catch ex As Exception
    >
    > ' write errors to the page
    >
    > Response.Write(ex.Message)
    >
    >
    >
    > End Try
    >
    >
    >
    >
    > Regards
    >
    > Daniel Walzenbach
    >
    >
    > "Michael D Murphy" <> schrieb im Newsbeitrag
    > news:ObT$...
    >>I corrected the problem with the SQLConnection.Open() -- I had to add the
    >>user ASPNET to the database. And that is another thing that bothers
    >>me--why didn't that error occur when I was previewing the data in the data
    >>adapter??
    >> My outstanding problem at this point is how do I track down errors
    >> (connection errors in this case) that occur on a page when the only tool
    >> I have is FTPing my files to the remote server.
    >>
    >> Thanks,
    >> Michael
    >>
    >>
    >> "Daniel Walzenbach" <> wrote in message
    >> news:OYo36$...
    >>> Michael,
    >>>
    >>>
    >>>
    >>> This will help you setting up your connection string.
    >>>
    >>> http://www.connectionstrings.com/
    >>>
    >>>
    >>>
    >>> What do you mean by "copy all the properties of that SQLConnection
    >>> object to a new SQLConnection"? Do you really mean all? Do you now have
    >>> two SQLConnection Objects having the same name? If you could provide us
    >>> with the error message you get it would me much easier to find a
    >>> solution to your problem.
    >>>
    >>> Basically I agree to what Jordan said. What I usually do is dragging a
    >>> SQLConnection of my form, copy the connection string, delete the
    >>> SQLConnection again and then create the SQLConnection in code behind
    >>> using the connection string I copied (I always forget about
    >>> theconnectionstrings.com).
    >>>
    >>>
    >>>
    >>> You should also have a look at the msdn reference which comes with some
    >>> nice examples:
    >>>
    >>> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> Does this help?
    >>>
    >>>
    >>>
    >>> Daniel Walzenbach
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> "Michael D Murphy" <> schrieb im
    >>> Newsbeitrag news:...
    >>>> Hi,
    >>>> I continually have problems with SQLConnections. Once I fix the one
    >>>> that I am having problems with I move on. I would rather have more
    >>>> confidence. I must be not understanding something or another. If I drag
    >>>> a SQLConnection to the form and configure it and then drag a
    >>>> SQLDataAdapter to the form and configure that, then right click on the
    >>>> SQLAdapter and click on Preview Data, I always get the data. But if I
    >>>> use that exact SQLConnection object or copy all the properties of that
    >>>> SQLConnection object to a new SQLConnection object, and try to connect
    >>>> I get errors. Why would it work one way and not the other. If you could
    >>>> point me to a SQLConnection primer or other tutorial that will finally
    >>>> get me past these problems, I would appreciate it.
    >>>> Thanks for your time,
    >>>> Michael
    >>>> 954-452-1047
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Michael D Murphy, Sep 5, 2005
    #15
  16. Michael,

    spend some time fiddling around with SQL Server Profiler. I found Profiler
    beeing one of the most useful tools! I'll have a look for a tutorial. One
    recommendation would be to have SQL Server Profiler running (you can use the
    config. I gave you for a start) while executing your application. This gives
    you a good idea about what is happening on the server. You will be
    surprised...

    Daniel Walzenbach


    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:...
    > Hi Daniel
    > I did what you suggested and noticed that the preview data used my windows
    > account to access the data and the code version of the access used ASPNET.
    > Kind of interesting! Also, this opens up some curiosities to begin using
    > some of these tools--THANKS!
    > If you can think of a webcast or tutorial that helps best use the tools,
    > that would be great!
    > In the mean time I will review the links that you have suggested.
    > Thanks Again,
    > Michael
    > "Daniel Walzenbach" <> wrote in message
    > news:OxP0$...
    >> Michael,
    >>
    >>
    >>
    >> to make things more clear to you I'd suggest the following:
    >>
    >>
    >>
    >> 1.) open query analyser and change to the database you are interested in.
    >> Execute the following statement:
    >>
    >>
    >>
    >> select DB_ID();
    >>
    >>
    >>
    >> remember the result.
    >>
    >>
    >>
    >> 2.) open SQL Server Profiler and create a new trace (File -> New ->
    >> Trace)
    >>
    >> 3.) open the Tab "Events" and remove everything except
    >>
    >> Stored Procedures, PRC: Completed,
    >>
    >> TSQL, SQL:BatchCompleted
    >>
    >>
    >>
    >> 4.) open the Tab "Filters" and set DatabaseID equals (the Number you
    >> selected in step 1)
    >>
    >>
    >>
    >> 5.) Preview the DataAdapter and see in Profiler which account is used
    >>
    >>
    >>
    >>
    >>
    >> What you now will see is the following:
    >>
    >> If you use the preview function your local user will be used.
    >>
    >> If you step through the code you'll see that the user defined in the
    >> connection string will be used...
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> This is a little example you might use:
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlConnection
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create the connection
    >>
    >> Dim mySQLConnection As New System.Data.SqlClient.SqlConnection
    >>
    >>
    >>
    >> Try
    >>
    >> ' assign the ConnectionString
    >>
    >> mySQLConnection.ConnectionString = "Initial Catalog=Northwind;Data
    >> Source=localhost;User ID=NorthwindUser;Password=xxxxxx;Packet Size=4096;"
    >>
    >>
    >>
    >> ' open the connection
    >>
    >> mySQLConnection.Open()
    >>
    >> Catch ex As Exception
    >>
    >> ' write errors to the page
    >>
    >> Response.Write(ex.Message)
    >>
    >>
    >>
    >> End Try
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlCommand
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a SQLCommand
    >>
    >> Dim mySQLCommand As New System.Data.SqlClient.SqlCommand
    >>
    >>
    >>
    >> ' assign the Connection to the Command
    >>
    >> mySQLCommand.Connection = mySQLConnection
    >>
    >>
    >>
    >> ' assign the SelectCommand
    >>
    >> mySQLCommand.CommandText = "SELECT [CustomerID], [CompanyName] FROM
    >> [Northwind].[dbo].[Customers]"
    >>
    >>
    >>
    >> ' assign the CommandType
    >>
    >> mySQLCommand.CommandType = CommandType.Text
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlDataAdapter
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a SqlDataAdapter
    >>
    >> Dim mySQLDataAdapter As New System.Data.SqlClient.SqlDataAdapter
    >>
    >>
    >>
    >> ' assign the SqlCommand to the SqlDataAdapter
    >>
    >> mySQLDataAdapter.SelectCommand = mySQLCommand
    >>
    >>
    >>
    >> ' assign TableMapping
    >>
    >> mySQLDataAdapter.TableMappings.Add("Table", "Customers")
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** DataSet
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a DataSet
    >>
    >> Dim myDataSet As New System.Data.DataSet
    >>
    >>
    >>
    >> Try
    >>
    >> ' fill the DataSet
    >>
    >> mySQLDataAdapter.Fill(myDataSet)
    >>
    >>
    >>
    >> Catch ex As Exception
    >>
    >> ' write errors to the page
    >>
    >> Response.Write(ex.Message)
    >>
    >>
    >>
    >> End Try
    >>
    >>
    >>
    >>
    >> Regards
    >>
    >> Daniel Walzenbach
    >>
    >>
    >> "Michael D Murphy" <> schrieb im
    >> Newsbeitrag news:ObT$...
    >>>I corrected the problem with the SQLConnection.Open() -- I had to add
    >>>the user ASPNET to the database. And that is another thing that bothers
    >>>me--why didn't that error occur when I was previewing the data in the
    >>>data adapter??
    >>> My outstanding problem at this point is how do I track down errors
    >>> (connection errors in this case) that occur on a page when the only tool
    >>> I have is FTPing my files to the remote server.
    >>>
    >>> Thanks,
    >>> Michael
    >>>
    >>>
    >>> "Daniel Walzenbach" <> wrote in
    >>> message news:OYo36$...
    >>>> Michael,
    >>>>
    >>>>
    >>>>
    >>>> This will help you setting up your connection string.
    >>>>
    >>>> http://www.connectionstrings.com/
    >>>>
    >>>>
    >>>>
    >>>> What do you mean by "copy all the properties of that SQLConnection
    >>>> object to a new SQLConnection"? Do you really mean all? Do you now have
    >>>> two SQLConnection Objects having the same name? If you could provide us
    >>>> with the error message you get it would me much easier to find a
    >>>> solution to your problem.
    >>>>
    >>>> Basically I agree to what Jordan said. What I usually do is dragging a
    >>>> SQLConnection of my form, copy the connection string, delete the
    >>>> SQLConnection again and then create the SQLConnection in code behind
    >>>> using the connection string I copied (I always forget about
    >>>> theconnectionstrings.com).
    >>>>
    >>>>
    >>>>
    >>>> You should also have a look at the msdn reference which comes with some
    >>>> nice examples:
    >>>>
    >>>> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> Does this help?
    >>>>
    >>>>
    >>>>
    >>>> Daniel Walzenbach
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> "Michael D Murphy" <> schrieb im
    >>>> Newsbeitrag news:...
    >>>>> Hi,
    >>>>> I continually have problems with SQLConnections. Once I fix the one
    >>>>> that I am having problems with I move on. I would rather have more
    >>>>> confidence. I must be not understanding something or another. If I
    >>>>> drag a SQLConnection to the form and configure it and then drag a
    >>>>> SQLDataAdapter to the form and configure that, then right click on the
    >>>>> SQLAdapter and click on Preview Data, I always get the data. But if I
    >>>>> use that exact SQLConnection object or copy all the properties of that
    >>>>> SQLConnection object to a new SQLConnection object, and try to connect
    >>>>> I get errors. Why would it work one way and not the other. If you
    >>>>> could point me to a SQLConnection primer or other tutorial that will
    >>>>> finally get me past these problems, I would appreciate it.
    >>>>> Thanks for your time,
    >>>>> Michael
    >>>>> 954-452-1047
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Daniel Walzenbach, Sep 5, 2005
    #16
  17. Great, thanks!
    Please keep my email address: just in case
    this message and thread gets removed from the newsgroup.
    Michael

    "Daniel Walzenbach" <> wrote in message
    news:%...
    > Michael,
    >
    > spend some time fiddling around with SQL Server Profiler. I found Profiler
    > beeing one of the most useful tools! I'll have a look for a tutorial. One
    > recommendation would be to have SQL Server Profiler running (you can use
    > the config. I gave you for a start) while executing your application. This
    > gives you a good idea about what is happening on the server. You will be
    > surprised...
    >
    > Daniel Walzenbach
    >
    >
    > "Michael D Murphy" <> schrieb im Newsbeitrag
    > news:...
    >> Hi Daniel
    >> I did what you suggested and noticed that the preview data used my
    >> windows account to access the data and the code version of the access
    >> used ASPNET. Kind of interesting! Also, this opens up some curiosities to
    >> begin using some of these tools--THANKS!
    >> If you can think of a webcast or tutorial that helps best use the tools,
    >> that would be great!
    >> In the mean time I will review the links that you have suggested.
    >> Thanks Again,
    >> Michael
    >> "Daniel Walzenbach" <> wrote in message
    >> news:OxP0$...
    >>> Michael,
    >>>
    >>>
    >>>
    >>> to make things more clear to you I'd suggest the following:
    >>>
    >>>
    >>>
    >>> 1.) open query analyser and change to the database you are interested
    >>> in. Execute the following statement:
    >>>
    >>>
    >>>
    >>> select DB_ID();
    >>>
    >>>
    >>>
    >>> remember the result.
    >>>
    >>>
    >>>
    >>> 2.) open SQL Server Profiler and create a new trace (File -> New ->
    >>> Trace)
    >>>
    >>> 3.) open the Tab "Events" and remove everything except
    >>>
    >>> Stored Procedures, PRC: Completed,
    >>>
    >>> TSQL, SQL:BatchCompleted
    >>>
    >>>
    >>>
    >>> 4.) open the Tab "Filters" and set DatabaseID equals (the Number you
    >>> selected in step 1)
    >>>
    >>>
    >>>
    >>> 5.) Preview the DataAdapter and see in Profiler which account is used
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> What you now will see is the following:
    >>>
    >>> If you use the preview function your local user will be used.
    >>>
    >>> If you step through the code you'll see that the user defined in the
    >>> connection string will be used...
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> This is a little example you might use:
    >>>
    >>>
    >>>
    >>> ' **********************************
    >>>
    >>> ' ** SqlConnection
    >>>
    >>> ' **********************************
    >>>
    >>>
    >>>
    >>> ' create the connection
    >>>
    >>> Dim mySQLConnection As New System.Data.SqlClient.SqlConnection
    >>>
    >>>
    >>>
    >>> Try
    >>>
    >>> ' assign the ConnectionString
    >>>
    >>> mySQLConnection.ConnectionString = "Initial Catalog=Northwind;Data
    >>> Source=localhost;User ID=NorthwindUser;Password=xxxxxx;Packet
    >>> Size=4096;"
    >>>
    >>>
    >>>
    >>> ' open the connection
    >>>
    >>> mySQLConnection.Open()
    >>>
    >>> Catch ex As Exception
    >>>
    >>> ' write errors to the page
    >>>
    >>> Response.Write(ex.Message)
    >>>
    >>>
    >>>
    >>> End Try
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> ' **********************************
    >>>
    >>> ' ** SqlCommand
    >>>
    >>> ' **********************************
    >>>
    >>>
    >>>
    >>> ' create a SQLCommand
    >>>
    >>> Dim mySQLCommand As New System.Data.SqlClient.SqlCommand
    >>>
    >>>
    >>>
    >>> ' assign the Connection to the Command
    >>>
    >>> mySQLCommand.Connection = mySQLConnection
    >>>
    >>>
    >>>
    >>> ' assign the SelectCommand
    >>>
    >>> mySQLCommand.CommandText = "SELECT [CustomerID], [CompanyName] FROM
    >>> [Northwind].[dbo].[Customers]"
    >>>
    >>>
    >>>
    >>> ' assign the CommandType
    >>>
    >>> mySQLCommand.CommandType = CommandType.Text
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> ' **********************************
    >>>
    >>> ' ** SqlDataAdapter
    >>>
    >>> ' **********************************
    >>>
    >>>
    >>>
    >>> ' create a SqlDataAdapter
    >>>
    >>> Dim mySQLDataAdapter As New System.Data.SqlClient.SqlDataAdapter
    >>>
    >>>
    >>>
    >>> ' assign the SqlCommand to the SqlDataAdapter
    >>>
    >>> mySQLDataAdapter.SelectCommand = mySQLCommand
    >>>
    >>>
    >>>
    >>> ' assign TableMapping
    >>>
    >>> mySQLDataAdapter.TableMappings.Add("Table", "Customers")
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> ' **********************************
    >>>
    >>> ' ** DataSet
    >>>
    >>> ' **********************************
    >>>
    >>>
    >>>
    >>> ' create a DataSet
    >>>
    >>> Dim myDataSet As New System.Data.DataSet
    >>>
    >>>
    >>>
    >>> Try
    >>>
    >>> ' fill the DataSet
    >>>
    >>> mySQLDataAdapter.Fill(myDataSet)
    >>>
    >>>
    >>>
    >>> Catch ex As Exception
    >>>
    >>> ' write errors to the page
    >>>
    >>> Response.Write(ex.Message)
    >>>
    >>>
    >>>
    >>> End Try
    >>>
    >>>
    >>>
    >>>
    >>> Regards
    >>>
    >>> Daniel Walzenbach
    >>>
    >>>
    >>> "Michael D Murphy" <> schrieb im
    >>> Newsbeitrag news:ObT$...
    >>>>I corrected the problem with the SQLConnection.Open() -- I had to add
    >>>>the user ASPNET to the database. And that is another thing that bothers
    >>>>me--why didn't that error occur when I was previewing the data in the
    >>>>data adapter??
    >>>> My outstanding problem at this point is how do I track down errors
    >>>> (connection errors in this case) that occur on a page when the only
    >>>> tool I have is FTPing my files to the remote server.
    >>>>
    >>>> Thanks,
    >>>> Michael
    >>>>
    >>>>
    >>>> "Daniel Walzenbach" <> wrote in
    >>>> message news:OYo36$...
    >>>>> Michael,
    >>>>>
    >>>>>
    >>>>>
    >>>>> This will help you setting up your connection string.
    >>>>>
    >>>>> http://www.connectionstrings.com/
    >>>>>
    >>>>>
    >>>>>
    >>>>> What do you mean by "copy all the properties of that SQLConnection
    >>>>> object to a new SQLConnection"? Do you really mean all? Do you now
    >>>>> have two SQLConnection Objects having the same name? If you could
    >>>>> provide us with the error message you get it would me much easier to
    >>>>> find a solution to your problem.
    >>>>>
    >>>>> Basically I agree to what Jordan said. What I usually do is dragging a
    >>>>> SQLConnection of my form, copy the connection string, delete the
    >>>>> SQLConnection again and then create the SQLConnection in code behind
    >>>>> using the connection string I copied (I always forget about
    >>>>> theconnectionstrings.com).
    >>>>>
    >>>>>
    >>>>>
    >>>>> You should also have a look at the msdn reference which comes with
    >>>>> some nice examples:
    >>>>>
    >>>>> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> Does this help?
    >>>>>
    >>>>>
    >>>>>
    >>>>> Daniel Walzenbach
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> "Michael D Murphy" <> schrieb im
    >>>>> Newsbeitrag news:...
    >>>>>> Hi,
    >>>>>> I continually have problems with SQLConnections. Once I fix the one
    >>>>>> that I am having problems with I move on. I would rather have more
    >>>>>> confidence. I must be not understanding something or another. If I
    >>>>>> drag a SQLConnection to the form and configure it and then drag a
    >>>>>> SQLDataAdapter to the form and configure that, then right click on
    >>>>>> the SQLAdapter and click on Preview Data, I always get the data. But
    >>>>>> if I use that exact SQLConnection object or copy all the properties
    >>>>>> of that SQLConnection object to a new SQLConnection object, and try
    >>>>>> to connect I get errors. Why would it work one way and not the other.
    >>>>>> If you could point me to a SQLConnection primer or other tutorial
    >>>>>> that will finally get me past these problems, I would appreciate it.
    >>>>>> Thanks for your time,
    >>>>>> Michael
    >>>>>> 954-452-1047
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Michael D Murphy, Sep 5, 2005
    #17
  18. Michael D Murphy

    Hans Kesting Guest

    Michael D Murphy wrote:
    > I corrected the problem with the SQLConnection.Open() -- I had to
    > add the user ASPNET to the database. And that is another thing that
    > bothers me--why didn't that error occur when I was previewing the
    > data in the data adapter??


    I think that when you work in the designer, Visual Studio uses *your* login
    to access the database (after all, *you* are the current user). When
    you test the application, that runs as ASPNET, so the connection is made
    as *that* user.
    We use sqlserver-login (=specify userid and pwd in the connection-string)
    instead of integrated security for this reason.

    Hans Kesting
     
    Hans Kesting, Sep 5, 2005
    #18
  19. Hans,

    I am sure you are aware that you should use integrated security when ever it
    is possible as is provides advanced security featured over SQL Server
    authoization.

    Regards

    Daniel Walzenbach


    "Hans Kesting" <> schrieb im Newsbeitrag
    news:...
    > Michael D Murphy wrote:
    >> I corrected the problem with the SQLConnection.Open() -- I had to
    >> add the user ASPNET to the database. And that is another thing that
    >> bothers me--why didn't that error occur when I was previewing the
    >> data in the data adapter??

    >
    > I think that when you work in the designer, Visual Studio uses *your*
    > login
    > to access the database (after all, *you* are the current user). When
    > you test the application, that runs as ASPNET, so the connection is made
    > as *that* user.
    > We use sqlserver-login (=specify userid and pwd in the connection-string)
    > instead of integrated security for this reason.
    >
    > Hans Kesting
    >
    >
     
    Daniel Walzenbach, Sep 6, 2005
    #19
  20. Michael,

    thy this link (I did not look it but the abstract looked quite good):
    http://go.microsoft.com/fwlink/?LinkId=22114


    Regards

    Daniel Walzenbach


    "Michael D Murphy" <> schrieb im Newsbeitrag
    news:...
    > Hi Daniel
    > I did what you suggested and noticed that the preview data used my windows
    > account to access the data and the code version of the access used ASPNET.
    > Kind of interesting! Also, this opens up some curiosities to begin using
    > some of these tools--THANKS!
    > If you can think of a webcast or tutorial that helps best use the tools,
    > that would be great!
    > In the mean time I will review the links that you have suggested.
    > Thanks Again,
    > Michael
    > "Daniel Walzenbach" <> wrote in message
    > news:OxP0$...
    >> Michael,
    >>
    >>
    >>
    >> to make things more clear to you I'd suggest the following:
    >>
    >>
    >>
    >> 1.) open query analyser and change to the database you are interested in.
    >> Execute the following statement:
    >>
    >>
    >>
    >> select DB_ID();
    >>
    >>
    >>
    >> remember the result.
    >>
    >>
    >>
    >> 2.) open SQL Server Profiler and create a new trace (File -> New ->
    >> Trace)
    >>
    >> 3.) open the Tab "Events" and remove everything except
    >>
    >> Stored Procedures, PRC: Completed,
    >>
    >> TSQL, SQL:BatchCompleted
    >>
    >>
    >>
    >> 4.) open the Tab "Filters" and set DatabaseID equals (the Number you
    >> selected in step 1)
    >>
    >>
    >>
    >> 5.) Preview the DataAdapter and see in Profiler which account is used
    >>
    >>
    >>
    >>
    >>
    >> What you now will see is the following:
    >>
    >> If you use the preview function your local user will be used.
    >>
    >> If you step through the code you'll see that the user defined in the
    >> connection string will be used...
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >> This is a little example you might use:
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlConnection
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create the connection
    >>
    >> Dim mySQLConnection As New System.Data.SqlClient.SqlConnection
    >>
    >>
    >>
    >> Try
    >>
    >> ' assign the ConnectionString
    >>
    >> mySQLConnection.ConnectionString = "Initial Catalog=Northwind;Data
    >> Source=localhost;User ID=NorthwindUser;Password=xxxxxx;Packet Size=4096;"
    >>
    >>
    >>
    >> ' open the connection
    >>
    >> mySQLConnection.Open()
    >>
    >> Catch ex As Exception
    >>
    >> ' write errors to the page
    >>
    >> Response.Write(ex.Message)
    >>
    >>
    >>
    >> End Try
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlCommand
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a SQLCommand
    >>
    >> Dim mySQLCommand As New System.Data.SqlClient.SqlCommand
    >>
    >>
    >>
    >> ' assign the Connection to the Command
    >>
    >> mySQLCommand.Connection = mySQLConnection
    >>
    >>
    >>
    >> ' assign the SelectCommand
    >>
    >> mySQLCommand.CommandText = "SELECT [CustomerID], [CompanyName] FROM
    >> [Northwind].[dbo].[Customers]"
    >>
    >>
    >>
    >> ' assign the CommandType
    >>
    >> mySQLCommand.CommandType = CommandType.Text
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** SqlDataAdapter
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a SqlDataAdapter
    >>
    >> Dim mySQLDataAdapter As New System.Data.SqlClient.SqlDataAdapter
    >>
    >>
    >>
    >> ' assign the SqlCommand to the SqlDataAdapter
    >>
    >> mySQLDataAdapter.SelectCommand = mySQLCommand
    >>
    >>
    >>
    >> ' assign TableMapping
    >>
    >> mySQLDataAdapter.TableMappings.Add("Table", "Customers")
    >>
    >>
    >>
    >>
    >>
    >> ' **********************************
    >>
    >> ' ** DataSet
    >>
    >> ' **********************************
    >>
    >>
    >>
    >> ' create a DataSet
    >>
    >> Dim myDataSet As New System.Data.DataSet
    >>
    >>
    >>
    >> Try
    >>
    >> ' fill the DataSet
    >>
    >> mySQLDataAdapter.Fill(myDataSet)
    >>
    >>
    >>
    >> Catch ex As Exception
    >>
    >> ' write errors to the page
    >>
    >> Response.Write(ex.Message)
    >>
    >>
    >>
    >> End Try
    >>
    >>
    >>
    >>
    >> Regards
    >>
    >> Daniel Walzenbach
    >>
    >>
    >> "Michael D Murphy" <> schrieb im
    >> Newsbeitrag news:ObT$...
    >>>I corrected the problem with the SQLConnection.Open() -- I had to add
    >>>the user ASPNET to the database. And that is another thing that bothers
    >>>me--why didn't that error occur when I was previewing the data in the
    >>>data adapter??
    >>> My outstanding problem at this point is how do I track down errors
    >>> (connection errors in this case) that occur on a page when the only tool
    >>> I have is FTPing my files to the remote server.
    >>>
    >>> Thanks,
    >>> Michael
    >>>
    >>>
    >>> "Daniel Walzenbach" <> wrote in
    >>> message news:OYo36$...
    >>>> Michael,
    >>>>
    >>>>
    >>>>
    >>>> This will help you setting up your connection string.
    >>>>
    >>>> http://www.connectionstrings.com/
    >>>>
    >>>>
    >>>>
    >>>> What do you mean by "copy all the properties of that SQLConnection
    >>>> object to a new SQLConnection"? Do you really mean all? Do you now have
    >>>> two SQLConnection Objects having the same name? If you could provide us
    >>>> with the error message you get it would me much easier to find a
    >>>> solution to your problem.
    >>>>
    >>>> Basically I agree to what Jordan said. What I usually do is dragging a
    >>>> SQLConnection of my form, copy the connection string, delete the
    >>>> SQLConnection again and then create the SQLConnection in code behind
    >>>> using the connection string I copied (I always forget about
    >>>> theconnectionstrings.com).
    >>>>
    >>>>
    >>>>
    >>>> You should also have a look at the msdn reference which comes with some
    >>>> nice examples:
    >>>>
    >>>> http://msdn.microsoft.com/library/d...ntSqlConnectionClassConnectionStringTopic.asp
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> Does this help?
    >>>>
    >>>>
    >>>>
    >>>> Daniel Walzenbach
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> "Michael D Murphy" <> schrieb im
    >>>> Newsbeitrag news:...
    >>>>> Hi,
    >>>>> I continually have problems with SQLConnections. Once I fix the one
    >>>>> that I am having problems with I move on. I would rather have more
    >>>>> confidence. I must be not understanding something or another. If I
    >>>>> drag a SQLConnection to the form and configure it and then drag a
    >>>>> SQLDataAdapter to the form and configure that, then right click on the
    >>>>> SQLAdapter and click on Preview Data, I always get the data. But if I
    >>>>> use that exact SQLConnection object or copy all the properties of that
    >>>>> SQLConnection object to a new SQLConnection object, and try to connect
    >>>>> I get errors. Why would it work one way and not the other. If you
    >>>>> could point me to a SQLConnection primer or other tutorial that will
    >>>>> finally get me past these problems, I would appreciate it.
    >>>>> Thanks for your time,
    >>>>> Michael
    >>>>> 954-452-1047
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >
     
    Daniel Walzenbach, Sep 6, 2005
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick Spiewak

    Re: SqlConnection problem

    Rick Spiewak, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    403
    Rick Spiewak
    Aug 27, 2003
  2. Amar
    Replies:
    3
    Views:
    359
    Trevor Benedict R
    Jun 11, 2004
  3. Claudiu Tescu

    SQLConnection Help

    Claudiu Tescu, Mar 31, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    454
    Brock Allen
    Mar 31, 2005
  4. Randy Smith
    Replies:
    3
    Views:
    385
    Randy Smith
    May 5, 2005
  5. Alan T

    SqlConnection problem - MySQL

    Alan T, Jul 19, 2010, in forum: ASP .Net
    Replies:
    5
    Views:
    1,062
    Leon Peon
    Jul 20, 2010
Loading...

Share This Page