Results 1 to 6 of 6

Thread: Use of SqlConnection Class

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    Use of SqlConnection Class

    Hi friends,

    I need you help to know about the 'SqlConnection' class. What is the use of "SqlConnection class"?. According to my knowledge it mey be related to the SQL database connection, But I am not confirmed on this. I wonder if you are able to give me some details about "SqlConnection class". It will be great if you provide any proper example of this class. Your any help would be appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Use of SqlConnection Class

    A SqlConnection class represents a unique session to a SQL data source. This class supports cross-form data binding with the Inter Form Technology. When you make an instance to the SqlConnection, entire properties are set to initial values. If the SqlConnection is out of it's scope, then it won't be closed. Therefore, you must explicitly close the connection by calling Close or Dispose. SqlConnection Class represents an open connection to an SQL Server database. This class cannot be inherited.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Use of SqlConnection Class

    SqlConnection class is normally used with SqlDataAdapter and SqlCommand to optimize performance when connecting to a database Microsoft SQL Server. In case of generation SqlException by executing the method SqlCommand, SqlConnection remains open when the severity level is less than or equal to 19. In other words, you can not execute a SQL statement while an asynchronous operation is in progress. When the severity level is greater than or equal to 20, the server closes normally SqlConnection. The User may reopen the connection and continue. For a list of these values, consult the manufacturer SqlConnection.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Use of SqlConnection Class

    Following is the example of SqlConnection Class:
    using System;
    using System.Data.SqlClient;

    class ProgramDem
    {
    static void Main()
    {

    using (SqlConnection con1 = new SqlConnection(connectionString))
    {


    con1.Open();

    using (SqlCommand command1 = new SqlCommand("SELECT TOP 2 * FROM Dogs1", con))

    using (SqlDataReader reader1 = command1.ExecuteReader())

    {
    while (reader1.Read())
    {
    Console.WriteLine("{0} {1} {2}",
    reader.GetInt32(0), reader1.GetString(1), reader1.GetString(2));
    }
    }
    }
    }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Use of SqlConnection Class

    With a database client / server, it is equivalent to a network connection to the server. SqlConnection class creates security demands by using the object SqlClientPermission. When you create an instance of SqlConnection class , all properties are set to their initial values.Users can verify that their code has sufficient permissions using the object SqlClientPermissionAttribute. Users can also use the Tool Code Access Security Policy Tool to modify security policy at the computer, user and enterprise. For more information, see Security in the. NET Framework. For an example describing how to use security demands, see Access Security and ADO.NET code.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Use of SqlConnection Class

    This class represents an open connection to the SQL Server database. There are various methods of SqlConnetion class. InitializeLifetimeService() method is used to tets a service object lifetime strategy for controlling lifetime in this forum. While the GetLifetimeService() methos is used for to gets the service object of life during which the control strategy of life in this forum. If the connection pooling value Pooling is set to true or yes, the underlying connection is returned back to the connection pool.

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. Sqlconnection state in C#.Net
    By Aramax in forum Windows Software
    Replies: 1
    Last Post: 08-06-2009, 11:47 PM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,294,824.29357 seconds with 17 queries