c#数据库网络编程的一个问题

SqlConnectionStringBuilder到底有什么用,怎么用?能不能通俗的讲一下啊?... SqlConnectionStringBuilder到底有什么用,怎么用?能不能通俗的讲一下啊? 展开
 我来答
百度网友8b9c67519
2012-02-15 · 超过21用户采纳过TA的回答
知道答主
回答量:55
采纳率:0%
帮助的人:40.9万
展开全部
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);
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ztq613
2012-02-15 · 超过18用户采纳过TA的回答
知道答主
回答量:119
采纳率:0%
帮助的人:64.5万
展开全部
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);
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式