本文整理汇总了C#中System.Configuration.ConnectionStringSettings类的典型用法代码示例。如果您正苦于以下问题:C# ConnectionStringSettings类的具体用法?C# ConnectionStringSettings怎么用?C# ConnectionStringSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionStringSettings类属于System.Configuration命名空间,在下文中一共展示了ConnectionStringSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteDatabase
public static void DeleteDatabase(ConnectionStringSettings connectionString)
{
var builder = new SqlConnectionStringBuilder(connectionString.ConnectionString);
string databaseName = builder.InitialCatalog;
builder.InitialCatalog = string.Empty;
using (var conn = new SqlConnection(builder.ConnectionString))
{
conn.Open();
using (var command = conn.CreateCommand())
{
command.CommandText = string.Format(
@"IF EXISTS(select * from sys.databases where name='{0}')
BEGIN
DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N'{0}'
DECLARE @Sql varchar(max)
SELECT @Sql = COALESCE(@Sql,'') + 'Kill ' + Convert(varchar, SPId) + ';'
FROM MASTER..SysProcesses
WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId
EXEC(@Sql)
DROP DATABASE [{0}]
END",
databaseName);
command.ExecuteNonQuery();
}
}
}
示例2: Assemble
/// <summary>
/// Builds an instance of the concrete subtype of <see cref="T:Microsoft.Practices.EnterpriseLibrary.Data.Database"/>
/// the receiver knows how to build, based on the provided connection string and any configuration information
/// that might be contained by the <paramref name="configurationSource"/>.
/// </summary>
/// <param name="name">The name for the new database instance.</param>
/// <param name="connectionStringSettings">The connection string for the new database instance.</param>
/// <param name="configurationSource">The source for any additional configuration information.</param>
/// <returns>
/// The new database instance.
/// </returns>
public Database Assemble(string name, ConnectionStringSettings connectionStringSettings,
IConfigurationSource configurationSource) {
if(IsDebugEnabled)
log.Debug("EnterpriseLibrary용 OracleProvider 인스턴스를 빌드합니다... name=[{0}]", name);
var settings = OracleConnectionSettings.GetSettings(configurationSource);
if(settings != null) {
var data = settings.OracleConnectionsData.Get(name);
if(data != null) {
var packages = new IOraclePackage[data.Packages.Count];
var num = 0;
foreach(var package in data.Packages) {
packages[num++] = package;
}
return new OracleDatabase(connectionStringSettings.ConnectionString);
}
}
if(IsDebugEnabled)
log.Debug("OracleDatabase를 생성합니다. connectionString=[{0}]", connectionStringSettings.ConnectionString);
return new OracleDatabase(connectionStringSettings.ConnectionString);
}
示例3: SqlBulkInsertOperation
/// <summary>
/// Initializes a new instance of the <see cref="SqlBulkInsertOperation"/> class.
/// </summary>
/// <param name="connectionStringSettings">Connection string settings to use.</param>
/// <param name="targetTable">The target table.</param>
/// <param name="timeout">The timeout.</param>
protected SqlBulkInsertOperation(ConnectionStringSettings connectionStringSettings, string targetTable, int timeout)
: base(connectionStringSettings)
{
Guard.Against(string.IsNullOrEmpty(targetTable), "TargetTable was not set, but it is mandatory");
this.targetTable = targetTable;
this.timeout = timeout;
}
示例4: GetNewOnMatch
internal static SqlCeProvider GetNewOnMatch(ConnectionStringSettings connectionConfig)
{
if (ProviderNames.Contains(connectionConfig.ProviderName))
return new SqlCeProvider(connectionConfig.Name, connectionConfig.ConnectionString, connectionConfig.ProviderName);
return null;
}
示例5: BuildConnectionString
protected virtual string BuildConnectionString(Guid streamId, ConnectionStringSettings setting)
{
if (this.shards == 0)
return setting.ConnectionString;
return setting.ConnectionString.FormatWith(this.ComputeHashKey(streamId));
}
示例6: DynamicModel
public DynamicModel(ConnectionStringSettings settings, DbProviderFactory factory)
{
Errors = new List<string>();
_dbProviderFactory = factory;
_connectionString = settings.ConnectionString;
}
示例7: GetConnectionStringsSection
static ConnectionStringsSection GetConnectionStringsSection()
{
ConnectionStringsSection section = new ConnectionStringsSection();
ConnectionStringSettings connectionStringSettings = new ConnectionStringSettings(instanceName, connectionString, providerName);
section.ConnectionStrings.Add(connectionStringSettings);
return section;
}
示例8: Create
public IDataProvider Create(ConnectionStringSettings settings, Transaction transactionMode)
{
var provider = ResolveDataProvider(settings.ProviderName);
provider.DbConnection = CreateConnection(settings.ProviderName, settings);
provider.TransactionMode = transactionMode;
return provider;
}
示例9: Main
static void Main(string[] args)
{
// Code that runs on application startup
ConnectionStringSettings cs = new ConnectionStringSettings("dbconnstring", HP.Rfg.lib.utility.getParameter("dbconnstring"), "System.Data.SqlClient");
string poolSize = HP.Rfg.lib.utility.getParameter("dbpoolsize");
int poolSizeInt = 5;
int.TryParse(poolSize, out poolSizeInt);
string pathToTempDir = utility.getParameter("path_to_temp");
HP.Rfg.Control.RFGActivator.StartApplication(cs, HP.Rfg.lib.utility.getParameter("smtp"), poolSizeInt, pathToTempDir);
MessageCallback_Console msg = new MessageCallback_Console();
try
{
BatchJobs.Process(pathToTempDir, msg);
System.Environment.Exit(0);
}
catch (Exception ex)
{
msg.AppendLine(ex.Message + "\n" + ex.StackTrace + "\n");
System.Environment.Exit(-1);
}
finally
{
HP.Rfg.Control.RFGActivator.StopApplication();
}
//}
}
示例10: CreateConnectionStringsConfig
///<summary>
///创建ConnectionString(如果存在,先删除再创建)
///</summary>
///<param name="config">Configuration实例</param>
///<param name="newName">连接字符串名称</param>
///<param name="newConString">连接字符串内容</param>
///<param name="newProviderName">数据提供程序名称</param>
public static Boolean CreateConnectionStringsConfig(Configuration config, string newName, string newConString, string newProviderName)
{
if (config == null && string.IsNullOrEmpty(newName) && string.IsNullOrEmpty(newConString) && string.IsNullOrEmpty(newProviderName))
{
return false;
}
bool isModified = false;
//记录该连接串是否已经存在
//如果要更改的连接串已经存在
if (config.ConnectionStrings.ConnectionStrings[newName] != null)
{ isModified = true; }
//新建一个连接字符串实例
ConnectionStringSettings mySettings = new ConnectionStringSettings(newName, newConString, newProviderName);
// 如果连接串已存在,首先删除它
if (isModified)
{
config.ConnectionStrings.ConnectionStrings.Remove(newName);
}
// 将新的连接串添加到配置文件中.
config.ConnectionStrings.ConnectionStrings.Add(mySettings);
// 保存对配置文件所作的更改
config.Save(ConfigurationSaveMode.Modified);
return true;
}
示例11: Initialize
public override void Initialize(string name, NameValueCollection config)
{
// Initialize values from web.config.
if (config == null) throw new ArgumentNullException("config");
if (name == null || name.Length == 0) name = "VauctionSessionStateStore";
if (String.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "Vauction Session State Store provider");
}
// Initialize the abstract base class.
base.Initialize(name, config);
// Initialize the ApplicationName property.
// Get <sessionState> configuration element.
System.Configuration.Configuration cfg = WebConfigurationManager.OpenWebConfiguration(ApplicationName);
pConfig = (SessionStateSection)cfg.GetSection("system.web/sessionState");
// Initialize connection string.
pConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
if (pConnectionStringSettings == null || pConnectionStringSettings.ConnectionString.Trim() == "")
throw new ProviderException("Connection string cannot be blank.");
connectionString = pConnectionStringSettings.ConnectionString;
// Initialize WriteExceptionsToEventLog
pWriteExceptionsToEventLog = false;
if (config["writeExceptionsToEventLog"] != null)
{
if (config["writeExceptionsToEventLog"].ToUpper() == "TRUE")
pWriteExceptionsToEventLog = true;
}
pApplicationName = (config["application"] != null) ? config["application"] : System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;
eventSource = (!String.IsNullOrEmpty(config["eventLogSource"])) ? config["eventLogSource"] : "VauctionSessionStateStore";
}
示例12: Parse
private ConnectionStringSettings Parse(ConnectionStringSettings connectionStringSettings)
{
var result = connectionStringSettings.ConnectionString;
result = ExpandEnvironmentVariables(result);
connectionStringSettings.ConnectionString = result;
return connectionStringSettings;
}
示例13: IndexOf
public int IndexOf (ConnectionStringSettings settings)
{
Contract.Requires (settings != null);
Contract.Ensures (Contract.Result<int>() >= -1);
return default(int);
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:7,代码来源:System.Configuration.ConnectionStringSettingsCollection.cs
示例14: InitDb
private static IDbConnectionProvider InitDb(DirectoryInfo baseDirectory)
{
if (baseDirectory == null)
{
var appdomainDirectory = AppDomain.CurrentDomain.BaseDirectory;
baseDirectory = new DirectoryInfo(Path.Combine(appdomainDirectory, "platibus", "subscriptions"));
}
var dbPath = Path.Combine(baseDirectory.FullName, "subscriptions.db");
var connectionStringSettings = new ConnectionStringSettings
{
Name = dbPath,
ConnectionString = "Data Source=" + dbPath + "; Version=3",
ProviderName = "System.Data.SQLite"
};
var connectionProvider = new SingletonConnectionProvider(connectionStringSettings);
var connection = connectionProvider.GetConnection();
try
{
using (var command = connection.CreateCommand())
{
command.CommandType = CommandType.Text;
command.CommandText = new SQLiteDialect().CreateSubscriptionTrackingServiceObjectsCommand;
command.ExecuteNonQuery();
}
}
finally
{
connectionProvider.ReleaseConnection(connection);
}
return connectionProvider;
}
示例15: GetDefaultConnectionStringSettings
private static ConnectionStringSettings GetDefaultConnectionStringSettings()
{
var connStrSettingsList = ConfigurationManager.ConnectionStrings;
ConnectionStringSettings defaultConnStrSettings = null;
for (int i = 0; i < connStrSettingsList.Count; ++i)
{
var connStrSettings = connStrSettingsList[i];
if ("default".Equals(connStrSettings.Name, StringComparison.OrdinalIgnoreCase))
{
if (defaultConnStrSettings != null)
{
throw new ConfigurationErrorsException("Multiple connection string settings with name \"default\"");
}
defaultConnStrSettings = connStrSettingsList[i];
if (string.IsNullOrEmpty(defaultConnStrSettings.ConnectionString))
{
throw new ConfigurationErrorsException("A connection string setting with name \"default\" has empty or null ConnectionString");
}
}
}
if (defaultConnStrSettings == null)
{
throw new ConfigurationErrorsException("No connection string settings with name \"default\"");
}
return defaultConnStrSettings;
}