Csharp/C Sharp/Database ADO.net/SqlCommandBuilder — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:42, 26 мая 2010
Содержание
ConnectionReset
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" Connection Reset = " + sb1.ConnectionReset);
SqlConnectionStringBuilder sb2 = new SqlConnectionStringBuilder(conString);
sb2.ConnectionReset = true;
Console.WriteLine(" " + sb2.ConnectionString);
}
}
Generate SQL command automatically from SqlCommandBuilder and SqlDataAdapter
using System;
using System.Data;
using System.Data.SqlClient;
class Class1{
static void Main(string[] args){
SqlConnection thisConnection = new SqlConnection("server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI");
thisConnection.Open();
SqlDataAdapter thisAdapter = new SqlDataAdapter("SELECT ID from Employee", thisConnection);
SqlCommandBuilder thisBuilder = new SqlCommandBuilder(thisAdapter);
Console.WriteLine("SQL SELECT Command is:\n{0}\n", thisAdapter.SelectCommand.rumandText);
SqlCommand updateCommand = thisBuilder.GetUpdateCommand();
Console.WriteLine("SQL UPDATE Command is:\n{0}\n", updateCommand.rumandText);
SqlCommand insertCommand = thisBuilder.GetInsertCommand();
Console.WriteLine("SQL INSERT Command is:\n{0}\n", insertCommand.rumandText);
SqlCommand deleteCommand = thisBuilder.GetDeleteCommand();
Console.WriteLine("SQL DELETE Command is:\n{0}", deleteCommand.rumandText);
thisConnection.Close();
}
}
IntegratedSecurity
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" Use Integrated Security = " + sb1.IntegratedSecurity);
SqlConnectionStringBuilder sb2 = new SqlConnectionStringBuilder(conString);
sb2.IntegratedSecurity = true;
Console.WriteLine(" " + sb2.ConnectionString);
}
}
LoadBalanceTimeout
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" Lifetime = " + sb1.LoadBalanceTimeout);
SqlConnectionStringBuilder sb2 = new SqlConnectionStringBuilder(conString);
sb2.LoadBalanceTimeout = 600;
Console.WriteLine(" " + sb2.ConnectionString);
}
}
MaxPoolSize
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" Max Pool Size = " + sb1.MaxPoolSize);
SqlConnectionStringBuilder sb2 = new SqlConnectionStringBuilder(conString);
sb2.MaxPoolSize = 15;
Console.WriteLine(" " + sb2.ConnectionString);
}
}
MinPoolSize
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" Min Pool Size = " + sb1.MinPoolSize);
SqlConnectionStringBuilder sb2 = new SqlConnectionStringBuilder(conString);
sb2.MinPoolSize = 5;
Console.WriteLine(" " + sb2.ConnectionString);
}
}
new SqlConnectionStringBuilder(conString)
using System;
using System.Data.SqlClient;
class MainClass {
public static void Main(string[] args) {
string conString = @"Data Source=.\sqlexpress;" +
"Database=Northwind;Integrated Security=SSPI;" +
"Min Pool Size=5;Max Pool Size=15;Connection Reset=True;" +
"Connection Lifetime=600;";
SqlConnectionStringBuilder sb1 = new SqlConnectionStringBuilder(conString);
Console.WriteLine(" " + sb1.ConnectionString);
}
}