Connectionstring only one word, I only say one

xiaoxiao2021-03-06  43

n

This thing is mainly to connect to the database,

Manager

There are many times inside.

n

String connStr =

"Workstation ID = overmind; packet

SIZE = 4096; user ID = sa; password = sa; data

Source = overmind; persist security info = false; initial

Catalog = WZTJ ";

n

We can use a general approach to let him only appear once, so

If our database server is modified, it is simple.

1------------------------------------------------- -------------------------------------------------- -

use

Web.config

n

n

When calling

CONFIGURATIONSETTINGS.

Appsettings ["

SqlConnectionstring

"];

The advantage of doing this is to define multiple

CONNECTION,

such as

SqlConnection

,

OracleConnection,

This

Real is a way to write attributes to

.property

or

.xml

Document practice.

2------------------------------------------------- -------------------------------------------------- ----------------------

Encapsulate

Connection

class

n

Just define your own

MyConnection,

Then put

Connectionstring

Write in.

n

When connecting, directly declare one

MyConnection,

then

Go back

Open

n

This is better, but it can only have one

Connection

3 ------------------------------------- -------------------------------------------------- -------------------

Define a static method of a class

n

Put the string of this connection in a class, such as this class

Be called

PROPERTIES

.

n

Then

Manager

You can call directly.

n

The benefits of this are more clear, or you can define multiple

CONNECTION,

And it is also very simple to transplant to other platforms. but

It's much more, it is more resource.

转载请注明原文地址:https://www.9cbs.com/read-54974.html

New Post(0)