且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ConnectionString属性尚未初始化。

更新时间:2022-10-25 22:52:57

Laura K写道:
尝试过各种各样的事情。我收到了错误。

ConnectionString属性尚未初始化。

任何帮助表示赞赏。

--------- -------------------------------------------------- ------------------------------------------
这是网络.config info

< configuration>

< appSettings>

< add key =" connectionstring" value =" Data Source =数据库的路径;
database = testingsite; User Id = UserID; Password = password" />

< / appSettings>

-------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------

这是提到的文件错误。

导入System.Data.SqlClient

公共类目录

公共共享函数GetDepartments()作为SqlDataReader
''创建连接对象

Dim连接为新SqlConnection(connectionString)
''创建并初始化命令对象

Dim命令As New SqlCommand(" dbo.GetDepartments",connection)

command.CommandType = CommandType.StoredProcedure

''打开连接

connection.Open()

''将SqlDataReader返回给调用函数

返回command.ExecuteReader(CommandBehavior.CloseConnect ion)

结束函数

私人共享Re adOnly属性connectionString()As String

获取

返回ConfigurationSettings.AppSettings(ConnectionStrin g)

结束获取

结束类




我知道标签在web.config中区分大小写。不记得

键/值的值。尝试更改

..AppSettings调用的大小写敏感度或配置中的键名称(使它们相同)。


-

Craig Deelsnyder

Microsoft MVP - ASP / ASP.NET


我尝试了十几个案例更改。这似乎不是。


还有其他想法吗?

Craig Deelsnyder &LT; cdeelsny@NO_SPAM_4_MEyahoo.com>在消息中写道

新闻:O4 ************** @ TK2MSFTNGP14.phx.gbl ...
Laura K写道:尝试过各种各样的事情。我收到了错误。

ConnectionString属性尚未初始化。

任何帮助表示赞赏。

--------- -------------------------------------------------- ------------------------------------------
这是网络.config info

< configuration>

< appSettings>

< add key =" connectionstring" value =" Data Source =数据库的路径;
database = testingsite; User Id = UserID; Password = password" />

< / appSettings>

-------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------

这是提到的文件错误。

导入System.Data.SqlClient

公共类目录

公共共享函数GetDepartments()作为SqlDataReader
''创建连接对象

Dim连接为新SqlConnection(connectionString)
''创建并初始化命令对象

Dim命令As New SqlCommand(" dbo.GetDepartments",connection)

command.CommandType = CommandType.StoredProcedure

''打开连接

connection.Open()

''将SqlDataReader返回给调用函数

返回command.ExecuteReader(CommandBehavior.CloseConnect ion)

结束函数

私人共享Re adOnly属性connectionString()As String

获取

返回ConfigurationSettings.AppSettings(ConnectionStrin g)

结束获取

结束类



我知道标签在web.config中区分大小写。不记得
键/值的值。尝试更改
.AppSettings调用的大小写敏感度或配置中的密钥名称(使它们相同)。

-
Craig Deelsnyder
Microsoft MVP - ASP / ASP.NET



试试这个: -

< add key =" ConnectionString" value ="数据源=(本地);

database = Northwind;综合安全性= SSPI />


请确认你正在通过应用中的正确密钥。


Patrick


***通过开发人员指南 http://www.developersdex.com 发送***


Tried all kinds of things. I get the error.

The ConnectionString property has not been initialized.

Any help appreciated.

-----------------------------------------------------------------------------------------------------
This is the web.config info

<configuration>

<appSettings>

<add key="connectionstring" value="Data Source=path to database;
database=testingsite;User Id=UserID;Password=password" />

</appSettings>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the doc mentioned in the error.

Imports System.Data.SqlClient

Public Class Catalog

Public Shared Function GetDepartments() As SqlDataReader

'' Create the connection object

Dim connection As New SqlConnection(connectionString)

'' Create and initialize the command object

Dim command As New SqlCommand("dbo.GetDepartments", connection)

command.CommandType = CommandType.StoredProcedure

'' Open the connection

connection.Open()

'' Return a SqlDataReader to the calling function

Return command.ExecuteReader(CommandBehavior.CloseConnect ion)

End Function

Private Shared ReadOnly Property connectionString() As String

Get

Return ConfigurationSettings.AppSettings("ConnectionStrin g")

End Get

End Property

End Class

Laura K wrote:
Tried all kinds of things. I get the error.

The ConnectionString property has not been initialized.

Any help appreciated.

-----------------------------------------------------------------------------------------------------
This is the web.config info

<configuration>

<appSettings>

<add key="connectionstring" value="Data Source=path to database;
database=testingsite;User Id=UserID;Password=password" />

</appSettings>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the doc mentioned in the error.

Imports System.Data.SqlClient

Public Class Catalog

Public Shared Function GetDepartments() As SqlDataReader

'' Create the connection object

Dim connection As New SqlConnection(connectionString)

'' Create and initialize the command object

Dim command As New SqlCommand("dbo.GetDepartments", connection)

command.CommandType = CommandType.StoredProcedure

'' Open the connection

connection.Open()

'' Return a SqlDataReader to the calling function

Return command.ExecuteReader(CommandBehavior.CloseConnect ion)

End Function

Private Shared ReadOnly Property connectionString() As String

Get

Return ConfigurationSettings.AppSettings("ConnectionStrin g")

End Get

End Property

End Class



I know the tags are case-sensitive in web.config. Can''t remember about
the keys/vals values. Try changing the case sensitivity of your
..AppSettings call or the key name in the config (make them the same).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET


I tried dozen of case changes. That doesn''t seem to be it.

Any other ideas?
"Craig Deelsnyder" <cdeelsny@NO_SPAM_4_MEyahoo.com> wrote in message
news:O4**************@TK2MSFTNGP14.phx.gbl...
Laura K wrote:
Tried all kinds of things. I get the error.

The ConnectionString property has not been initialized.

Any help appreciated.

-----------------------------------------------------------------------------------------------------
This is the web.config info

<configuration>

<appSettings>

<add key="connectionstring" value="Data Source=path to database;
database=testingsite;User Id=UserID;Password=password" />

</appSettings>

-------------------------------------------------------------------------------------------------------------------------------------------------------------------

Here is the doc mentioned in the error.

Imports System.Data.SqlClient

Public Class Catalog

Public Shared Function GetDepartments() As SqlDataReader

'' Create the connection object

Dim connection As New SqlConnection(connectionString)

'' Create and initialize the command object

Dim command As New SqlCommand("dbo.GetDepartments", connection)

command.CommandType = CommandType.StoredProcedure

'' Open the connection

connection.Open()

'' Return a SqlDataReader to the calling function

Return command.ExecuteReader(CommandBehavior.CloseConnect ion)

End Function

Private Shared ReadOnly Property connectionString() As String

Get

Return ConfigurationSettings.AppSettings("ConnectionStrin g")

End Get

End Property

End Class



I know the tags are case-sensitive in web.config. Can''t remember about
the keys/vals values. Try changing the case sensitivity of your
.AppSettings call or the key name in the config (make them the same).

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET



Try this:-
<add key="ConnectionString" value="Data Source=(local);
database=Northwind; Integrated Security=SSPI" />

MAKE SURE U ARE PASSING THE CORRECT KEY IN UR APPLICATION.

Patrick

*** Sent via Developersdex http://www.developersdex.com ***