SQL Server From .Net: Making A Connection

  • Comments posted to this topic are about the item SQL Server From .Net: Making A Connection

  • The article isn't available

  • Working now on this link: http://www.sqlservercentral.com/articles/ADO.NET/168710/
    But not the one at the top of this page (https://www.sqlservercentral.com/articles/C%23/168710/)

  • Yeah, the escaping the tag sequence for C# is broken. I'll edit the one in the forum

  • The link in the daily email worked for me.

  • Here is my list of other topics I have thought of for other articles on working with SQL Server in .Net

    Data sets and representation of relationships and constraints in .Net code (The first draft of this article is almost ready for submission.)
    Data types and what they convert to when you query SQL Server from .Net
    Different ways of doing the data conversion 
    Techniques for converting data for display etc.
    Dealing with nulls in data
    How to avoid SQL injection in your .Net web app
    Connecting LINQ to SQL Server
    Dealing with concurrency
    Catching data exceptions
    Debugging
    Working with Schemas in .Net

    I am interested in hearing any other ideas, and also the issues that might be helpful for developers (or DBAs) working with SQL Server data in .Net to know about.

  • timwell - Monday, April 16, 2018 9:41 AM

    The link in the daily email worked for me.

    There's a redirect there. I'd probably fixed it by the time you clicked.

  • timwell - Monday, April 16, 2018 9:54 AM

    Here is my list of other topics I have thought of for other articles on working with SQL Server in .Net

    Data sets and representation of relationships and constraints in .Net code (The first draft of this article is almost ready for submission.)
    Data types and what they convert to when you query SQL Server from .Net
    Different ways of doing the data conversion 
    Techniques for converting data for display etc.
    Dealing with nulls in data
    How to avoid SQL injection in your .Net web app
    Connecting LINQ to SQL Server
    Dealing with concurrency
    Catching data exceptions
    Debugging
    Working with Schemas in .Net

    I am interested in hearing any other ideas, and also the issues that might be helpful for developers (or DBAs) working with SQL Server data in .Net to know about.

    Great info, but when using objects that are disposable, you should use a using statement, so the connection or command are automatically closed and disposed. Alleviates code in the catch block

  • This is a really useful article.

    If you are looking for an idea on an article to write.  Using Windows forms for multiline user input/output (Adding and editing multi line records) in C# connecting into a stored procedure in MS SQL Server to control the final input to and from the database.

  • louie1487 78804 - Monday, April 16, 2018 11:04 AM

    timwell - Monday, April 16, 2018 9:54 AM

    Great info, but when using objects that are disposable, you should use a using statement, so the connection or command are automatically closed and disposed. Alleviates code in the catch block

    Hello, Thanks, that is a good point. I have not gotten into that habit. Something like this I think?
       using (SqlConnection conn1 = new SqlConnection(connectString))
        {
           conn1.Open();
           conn1.DoStuffWithTheConnection();
           //...
           conn1.Close();
        }

  • timwell - Monday, April 16, 2018 3:02 PM

    louie1487 78804 - Monday, April 16, 2018 11:04 AM

    timwell - Monday, April 16, 2018 9:54 AM

    Great info, but when using objects that are disposable, you should use a using statement, so the connection or command are automatically closed and disposed. Alleviates code in the catch block

    Hello, Thanks, that is a good point. I have not gotten into that habit. Something like this I think?
       using (SqlConnection conn1 = new SqlConnection(connectString))
        {
           conn1.Open();
           conn1.DoStuffWithTheConnection();
           //...
           conn1.Close();
        }

    Yep

  • Thanks for sharing.
    I may be wrong but I don't think any of the SqlConnection constructors throws exceptions (cfr https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.sqlconnection(v=vs.110).aspx)
    So the try/catch shouldn't be necessary when creating it, only when opening the connection

  • Paul_clarke - Monday, April 16, 2018 2:58 PM

    This is a really useful article.

    If you are looking for an idea on an article to write.  Using Windows forms for multiline user input/output (Adding and editing multi line records) in C# connecting into a stored procedure in MS SQL Server to control the final input to and from the database.

    Thanks for the suggestion. Is that one topic or two, multi-line I/O and connecting using stored procedures? By multiline do you mean like in a DataGrid or just passing multiple rows to and from like with a DataSet?

  • thierry.vandurme - Tuesday, April 17, 2018 6:18 AM

    Thanks for sharing.
    I may be wrong but I don't think any of the SqlConnection constructors throws exceptions (cfr https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.sqlconnection(v=vs.110).aspx)
    So the try/catch shouldn't be necessary when creating it, only when opening the connection

    By supplying a really incorrect connection string I was able to cause an ArgumentException exception. That is why I included the try/catch for that.
    It's not thrown by the constructor itself but when it's parsing the string. 
    If your formatting is good enough adding a try/catch for that might be more than necessary.

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic. Login to reply