how to open and close connection using sqlconnectionstringbuilder  
Author Message
pukla





PostPosted: .NET Framework Data Access and Storage, how to open and close connection using sqlconnectionstringbuilder Top

hi, im trying to do some experiment using sqlconnectionstring and sqlconnectionstringbuilder. how do i close the connection using sqlconnectionstringbuilder


.NET Development24  
 
 
Ronald Ricardo Ramirez Moran





PostPosted: .NET Framework Data Access and Storage, how to open and close connection using sqlconnectionstringbuilder Top

The SqlConnectionStringBuilder, only allows to you to generate a SQL Server compliant Connection-String, to open or close a Connection you need to create a new SqlConnection and adding the generated Connection String. For example:

SqlStringBuilder sb = new SqlStringBuilder();
// Sets the respective properties
using (SqlConnection cnn = new SqlConnection(sb.ToString()))
{
   cnn.Open();
   /// Create a command and execute it
   cnn.Close();
}

Regards



 
 
pukla





PostPosted: .NET Framework Data Access and Storage, how to open and close connection using sqlconnectionstringbuilder Top

if that's the case, then i should use sqlconnectionstring instead, so that i can open and close my connection
 
 
iamunmad





PostPosted: .NET Framework Data Access and Storage, how to open and close connection using sqlconnectionstringbuilder Top

U cannot open or close a SqlConnection using SqlConnectionStringBuilder. SqlConnectionStringBuilder provides functionality to create error free connection string which can be later use by any connection object.