web.config问题2.0 [英] web.config question 2.0
问题描述
我的应用程序中有一个web.config,其中包含连接字符串
到我的所有数据源。我想将这些连接字符串移动到另一个
web配置文件夹层次结构,以便我的所有应用程序都可以使用相同的
连接字符串。这应该是怎么做的,不是吗? web.config位于c:\inetpub \ www.root \ myApp \web.config中,而不是
c:\inetpub \\ \\wwwroot\web.config。但是,我得到一个对象引用没有设置
到一个对象的实例。我这样做时出错。这曾经在Visual Studio 2003 .net 1.0中运行良好
。
我的连接字符串很好:
< connectionStrings>
< add name =" myDB" connectionString =" Data Source = mySvr; Initial
Catalog = myDB; Integrated Security = True" />
< / connectionStrings>
这就是我在网络应用中检索的方式:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings(" ; myDB")。ToString
我做错了什么?
感谢您的帮助。
I have a web.config in my application that contains the connection strings
to all my datasources. I want to move these connection strings to another
web config up the folder hierarchy so that all my apps can use the same
connection strings. That is supposed to be how it''s done, no? Instead of
the web.config being in c:\inetpub\wwwroot\myApp\web.config, I have it in
c:\inetpub\wwwroot\web.config. However, I get an "Object reference not set
to an instance of an object" error when I do this. This used to work fine
in Visual Studio 2003 .net 1.0.
My connection string is fine:
<connectionStrings>
<add name="myDB" connectionString="Data Source=mySvr;Initial
Catalog=myDB;Integrated Security=True "/>
</connectionStrings>
And this is how I retrieve in in the web app:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings("myDB").ToString
What am I doing wrong?
Thanks for your help.
推荐答案
尝试使用
连接字符串的数据源部分的完整路径,因为您正在使用相对数据源更改
Web.config的位置可能会导致问题。
-
Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/
" eagle" < ea ************* @ yahoo.comwrote in message
news:Op ************* @ TK2MSFTNGP06.phx .gbl ...
Try using the complete path for the Data Source section of your
connectionstring, because you are using a relative Data Source changing the
location of your Web.config might cause a problem.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
"eagle" <ea*************@yahoo.comwrote in message
news:Op*************@TK2MSFTNGP06.phx.gbl...
>我的应用程序中有一个web.config,其中包含连接字符串
到我的所有数据源。我想将这些连接字符串移动到另一个
web配置文件夹层次结构,以便我的所有应用程序都可以使用相同的
连接字符串。这应该是怎么做的,不是吗? web.config位于c:\inetpub \ www.root \ myApp \web.config中,而不是
c:\inetpub \\ \\wwwroot\web.config。但是,我得到一个对象引用不是
设置
到一个对象的实例我这样做时出错。这曾经在Visual Studio 2003 .net 1.0中运行良好
。
我的连接字符串很好:
< connectionStrings>
< add name =" myDB" connectionString =" Data Source = mySvr; Initial
Catalog = myDB; Integrated Security = True" />
< / connectionStrings>
这就是我在网络应用中检索的方式:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings(" ; myDB")。ToString
我做错了什么?
感谢您的帮助。
>I have a web.config in my application that contains the connection strings
to all my datasources. I want to move these connection strings to another
web config up the folder hierarchy so that all my apps can use the same
connection strings. That is supposed to be how it''s done, no? Instead of
the web.config being in c:\inetpub\wwwroot\myApp\web.config, I have it in
c:\inetpub\wwwroot\web.config. However, I get an "Object reference not
set
to an instance of an object" error when I do this. This used to work fine
in Visual Studio 2003 .net 1.0.
My connection string is fine:
<connectionStrings>
<add name="myDB" connectionString="Data Source=mySvr;Initial
Catalog=myDB;Integrated Security=True "/>
</connectionStrings>
And this is how I retrieve in in the web app:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings("myDB").ToString
What am I doing wrong?
Thanks for your help.
re:
!我想将这些连接字符串移动到另一个web配置
!文件夹层次结构中所有我的应用程序都可以使用相同的连接字符串。
是的,你可以这样做。
re:
!那应该是怎么做的,不是吗?
不确定这是不是*它应该是*,但它*可以*完成。
我想这是开发人员的选择,无论你是否这样做,
或是否存储每个应用程序在每个应用程序的web.config中的连接字符串。
re:
!>我的连接字符串很好:
! < connectionStrings>
! < add name =" myDB" connectionString =" Data Source = mySvr; Initial
!Catalog = myDB; Integrated Security = True" />
!< / connectionStrings>
是的,这很好......对于应用程序的web.config中的连接字符串,'
但不适用于web.config up文件夹层次结构。
re:
!我做错了什么?
你没有配置root web.config作为从中检索值的那个。
试试这个:
Dim configPath As String =" /"
''这得到根web.config
Dim config As ConnectionStringsSection = WebConfigurationManager.GetWebApplicationSection(" connectionStrings")
''this将connectionStrings部分声明为要从中检索值的部分
Dim value as String ="已配置的connectionStrings连接是:" &安培; config.connectionstrings(" myDB")。ToString()
''这将检索连接字符串myDB的值
Juan T. Llibre,asp.net MVP
asp.net faq: http: //asp.net.do/faq/
foros de asp.net,en espa?ol: http://asp.net.do/foros/
============== ========================
" eagle" < ea ************* @ yahoo.com在消息新闻中写道:Op ************* @ TK2MSFTNGP06.phx.gbl ...
re:
!I want to move these connection strings to another web config up the
!folder hierarchy so that all my apps can use the same connection strings.
Yes, you can do that.
re:
!That is supposed to be how it''s done, no?
Not sure if that''s how it''s *supposed* to be, but it *can* be done.
I suppose it''s a developer choice whether you do that, or not,
or whether you store each app''s connection strings in each app''s web.config.
re:
!>My connection string is fine:
! <connectionStrings>
! <add name="myDB" connectionString="Data Source=mySvr;Initial
!Catalog=myDB;Integrated Security=True "/>
!</connectionStrings>
Yes, that''s fine...for a connection string in your app''s web.config,''
but not for a web.config up the folder hierarchy.
re:
!What am I doing wrong?
You are not configuring the root web.config as the one to retrieve the value from.
Try this :
Dim configPath As String = "/"
'' this gets the root web.config
Dim config As ConnectionStringsSection = WebConfigurationManager.GetWebApplicationSection(" connectionStrings")
'' this declares the connectionStrings section as the one you want to retrieve the value from
Dim value as String = "The configured connectionStrings connection is : " & config.connectionstrings("myDB").ToString()
'' this retrieves the value for the connection string "myDB"
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
======================================
"eagle" <ea*************@yahoo.comwrote in message news:Op*************@TK2MSFTNGP06.phx.gbl...
>我的应用程序中有一个web.config,其中包含连接字符串
到我的所有数据源。我想将这些连接字符串移动到另一个
web配置文件夹层次结构,以便我的所有应用程序都可以使用相同的
连接字符串。这应该是怎么做的,不是吗? web.config位于c:\inetpub \ www.root \ myApp \web.config中,而不是
c:\inetpub \\ \\wwwroot\web.config。但是,我得到一个对象引用没有设置
到一个对象的实例。我这样做时出错。这曾经在Visual Studio 2003 .net 1.0中运行良好
。
我的连接字符串很好:
< connectionStrings>
< add name =" myDB" connectionString =" Data Source = mySvr; Initial
Catalog = myDB; Integrated Security = True" />
< / connectionStrings>
这就是我在网络应用中检索的方式:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings(" ; myDB")。ToString
我做错了什么?
感谢您的帮助。
>I have a web.config in my application that contains the connection strings
to all my datasources. I want to move these connection strings to another
web config up the folder hierarchy so that all my apps can use the same
connection strings. That is supposed to be how it''s done, no? Instead of
the web.config being in c:\inetpub\wwwroot\myApp\web.config, I have it in
c:\inetpub\wwwroot\web.config. However, I get an "Object reference not set
to an instance of an object" error when I do this. This used to work fine
in Visual Studio 2003 .net 1.0.
My connection string is fine:
<connectionStrings>
<add name="myDB" connectionString="Data Source=mySvr;Initial
Catalog=myDB;Integrated Security=True "/>
</connectionStrings>
And this is how I retrieve in in the web app:
_sSQLConn =
System.Configuration.ConfigurationManager.Connecti onStrings("myDB").ToString
What am I doing wrong?
Thanks for your help.
" Juan T. Llibre" < no *********** @ nowhere.comwrote in message
news:O6 ************** @ TK2MSFTNGP02.phx。 gbl ...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:O6**************@TK2MSFTNGP02.phx.gbl...
我认为这是开发人员的选择,无论你是否这样做,
或者你是否存储每个应用程序每个应用程序中的连接字符串
web.config。
I suppose it''s a developer choice whether you do that, or not,
or whether you store each app''s connection strings in each app''s
web.config.
我总是选择后者...
I always go for the latter...
Dim configPath As String =" /" ;
Dim config As ConnectionStringsSection =
WebConfigurationManager.GetWebApplicationSection(" connectionStrings")
Dim value as String ="已配置的connectionStrings连接是:
& config.connectionstrings(" myDB")。ToString()
Dim configPath As String = "/"
Dim config As ConnectionStringsSection =
WebConfigurationManager.GetWebApplicationSection(" connectionStrings")
Dim value as String = "The configured connectionStrings connection is : "
& config.connectionstrings("myDB").ToString()
你确定吗?你要声明一个configPath变量指向
根web.config,但实际上并没有在任何地方使用它......
-
Mark Rae
ASP.NET MVP
http:/ /www.markrae.net
Are you sure about this? You''re declaring a configPath variable to point to
the root web.config, but then not actually using it anywhere...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net
这篇关于web.config问题2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!