c#数据库网络编程的一个问题
SqlConnectionStringBuilder到底有什么用,怎么用?能不能通俗的讲一下啊?...
SqlConnectionStringBuilder到底有什么用,怎么用?能不能通俗的讲一下啊?
展开
2个回答
展开全部
SqlConnectionStringBuilder builder =
new SqlConnectionStringBuilder(GetConnectionString());
// The input connection string used the
// Server key, but the new connection string uses
// the well-known Data Source key instead.
Console.WriteLine(builder.ConnectionString);
// Pass the SqlConnectionStringBuilder an existing
// connection string, and you can retrieve and
// modify any of the elements.
builder.ConnectionString = "server=(local);user id=ab;" +
"password= a!Pass113;initial catalog=AdventureWorks";
// Now that the connection string has been parsed,
// you can work with individual items.
Console.WriteLine(builder.Password);
builder.Password = "new@1Password";
builder.AsynchronousProcessing = true;
// You can refer to connection keys using strings,
// as well. When you use this technique (the default
// Item property in Visual Basic, or the indexer in C#),
// you can specify any synonym for the connection string key
// name.
builder["Server"] = ".";
builder["Connect Timeout"] = 1000;
builder["Trusted_Connection"] = true;
Console.WriteLine(builder.ConnectionString);
new SqlConnectionStringBuilder(GetConnectionString());
// The input connection string used the
// Server key, but the new connection string uses
// the well-known Data Source key instead.
Console.WriteLine(builder.ConnectionString);
// Pass the SqlConnectionStringBuilder an existing
// connection string, and you can retrieve and
// modify any of the elements.
builder.ConnectionString = "server=(local);user id=ab;" +
"password= a!Pass113;initial catalog=AdventureWorks";
// Now that the connection string has been parsed,
// you can work with individual items.
Console.WriteLine(builder.Password);
builder.Password = "new@1Password";
builder.AsynchronousProcessing = true;
// You can refer to connection keys using strings,
// as well. When you use this technique (the default
// Item property in Visual Basic, or the indexer in C#),
// you can specify any synonym for the connection string key
// name.
builder["Server"] = ".";
builder["Connect Timeout"] = 1000;
builder["Trusted_Connection"] = true;
Console.WriteLine(builder.ConnectionString);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
using System.Data.SqlClient;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = Environment.MachineName; // builder["server"]
builder.InitialCatalog = "ProductSet"; // builder["database"]
builder.IntegratedSecurity = true; // builder["trusted_connection"]
builder.TypeSystemVersion = "SQL Server 2000"; // builder["Type System Version"]
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = string.Format(@"{0}\SQLEXPRESS", Environment.MachineName);
builder.InitialCatalog = "ProductSet";
builder.IntegratedSecurity = true;
builder.TypeSystemVersion = "SQL Server 2005";
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = string.Format(@"{0}\SQLEXPRESS", Environment.MachineName); // Environment.MachineName <=> "." 本地服务器名。
builder.AttachDBFilename = @"|DataDirectory|\ProductSet.mdf";
builder.IntegratedSecurity = true;
builder.UserInstance = true;
builder.TypeSystemVersion = "SQL Server 2008";
SqlConnection sql = new SqlConnection(builder.ConnectionString);
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = Environment.MachineName; // builder["server"]
builder.InitialCatalog = "ProductSet"; // builder["database"]
builder.IntegratedSecurity = true; // builder["trusted_connection"]
builder.TypeSystemVersion = "SQL Server 2000"; // builder["Type System Version"]
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = string.Format(@"{0}\SQLEXPRESS", Environment.MachineName);
builder.InitialCatalog = "ProductSet";
builder.IntegratedSecurity = true;
builder.TypeSystemVersion = "SQL Server 2005";
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.DataSource = string.Format(@"{0}\SQLEXPRESS", Environment.MachineName); // Environment.MachineName <=> "." 本地服务器名。
builder.AttachDBFilename = @"|DataDirectory|\ProductSet.mdf";
builder.IntegratedSecurity = true;
builder.UserInstance = true;
builder.TypeSystemVersion = "SQL Server 2008";
SqlConnection sql = new SqlConnection(builder.ConnectionString);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |