可以从文件中获取SQL Server 2005中的连接字符串吗?

时间:2021-12-17 13:20:26

I have created a web enabled DB for a company as a part of my internship and it's up and ready. However the connection string of the server is already coded by me. But the IT guy said that he wanted me to read the connection string from a file containing various connection strings and choosing whichever it wanted to at that time.

作为实习的一部分,我为公司创建了一个支持Web的数据库,并且已经准备就绪。但是,服务器的连接字符串已由我编码。但IT人员说他希望我从包含各种连接字符串的文件中读取连接字符串,并选择当时想要的连接字符串。

My question is, Is it possible???....If Yes How???

我的问题是,是否可能??? ....如果是如何???

Kindly help me...i had a long session with him trying to understand the concept, still could'nt get it.

请帮助我...我和他一起试图了解这个概念,但仍然无法得到它。

Thanking in anticipation Sujit

感谢期待Sujit

2 个解决方案

#1


4  

How to: Read Connection Strings from the Web.config File

如何:从Web.config文件中读取连接字符串

#2


1  

This shouldn't be a problem.

这应该不是问题。

Put the connection string in a file, read the file in your program and pass the string in to the database connection object you are using.

将连接字符串放在一个文件中,读取程序中的文件并将字符串传递给您正在使用的数据库连接对象。

This is so common that in .NET the configuration file schema already has a place for connection strings (plus mechanisms to encrypt that section).

这很常见,在.NET中,配置文件模式已经有了连接字符串的位置(加上加密该部分的机制)。

Update:

更新:

As you indicate that you are using .NET, you should look into the app.config file, in particular the ConfigurationMananger and the ConnectionStrings section/property.

当您指示使用.NET时,应该查看app.config文件,特别是ConfigurationMananger和ConnectionStrings部分/属性。

#1


4  

How to: Read Connection Strings from the Web.config File

如何:从Web.config文件中读取连接字符串

#2


1  

This shouldn't be a problem.

这应该不是问题。

Put the connection string in a file, read the file in your program and pass the string in to the database connection object you are using.

将连接字符串放在一个文件中,读取程序中的文件并将字符串传递给您正在使用的数据库连接对象。

This is so common that in .NET the configuration file schema already has a place for connection strings (plus mechanisms to encrypt that section).

这很常见,在.NET中,配置文件模式已经有了连接字符串的位置(加上加密该部分的机制)。

Update:

更新:

As you indicate that you are using .NET, you should look into the app.config file, in particular the ConfigurationMananger and the ConnectionStrings section/property.

当您指示使用.NET时,应该查看app.config文件,特别是ConfigurationMananger和ConnectionStrings部分/属性。