English 中文(简体)
2. 如何改变显示初步数据交换的连接
原标题:how to change connection string initial catalog

I have a connection string in web config file. I used this connection with name in all my files.

连接线象

<add name="connectionname" connectionString="Data Source=DEVELOPER1;Initial Catalog=dbname;Persist Security Info=True;User ID=sa;Password=some"/>

我想要将原木本页的原始数据表(数据库名称)改为每滴,这一改动对申请来说将保持不变。

问题回答

为了在不作修改的情况下改变这种联系,你应当采取以下程序:

  1. Create a SqlConnectionStringBuilder object Assign your original connection string to it
  2. Change the parameters that you want in the created SqlConnectionStringBuilder object.
  3. Adding the SqlConnectionStringBuilder ConnectionString property to your DbConnection Object.

参看以下例子:(假设首先,你是用你原来的拼凑(此处称db))创造出正常的DbConnection:

if (db != null)
{
    SqlConnectionStringBuilder conn = new SqlConnectionStringBuilder(db.ConnectionString)
   { ConnectTimeout = 5, InitialCatalog = "your CatalogName" }; // you can add other parameters.
      db.ConnectionString = conn.ConnectionString;
      db.Open();
      return true;
   }
}

In the given example, the Initial Catalog and the timeout were changed without touch the original string.

我希望这有助于你。

我认为,每个数据库都需要连接。

用户选择连接的灯塔会下降。 这种价值需要坚持下去,或许是在届会期间。

你们需要一个班子,负责提供显示价值的联系。 这一类别从本届会议中减去了价值,并恢复了与你的DAL职能相关的适当联系。

编辑:如果你在你的所有网页上都使用显示链接的名称,你将不得不加以改动。 概述可能发生的变化。 搜查和替换可能会发生吗?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签