By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,743 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,743 IT Pros & Developers. It's quick & easy.

Q: connection problem

P: n/a
Hello,
What is wong with the following code I am getting “ The ConnectionString
property has not been initialized”

Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)

myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub

mySP is a stored procedure wihh is simple “select * from myTable”
Thanks,
Jim.

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

That's an awfully long name for an appSetting name...

appSettings is a name/value Collection. If you have a Connection String
stored there, you should refer to it by name.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hello,
What is wong with the following code I am getting " The ConnectionString
property has not been initialized"

Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)

myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub

mySP is a stored procedure wihh is simple "select * from myTable"
Thanks,
Jim.

Nov 19 '05 #2

P: n/a
Kevin, can you me more clear, where can I store connStr? can you give
example, I am new in asp.net

"Kevin Spencer" wrote:
Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

That's an awfully long name for an appSetting name...

appSettings is a name/value Collection. If you have a Connection String
stored there, you should refer to it by name.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hello,
What is wong with the following code I am getting " The ConnectionString
property has not been initialized"

Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)

myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub

mySP is a stored procedure wihh is simple "select * from myTable"
Thanks,
Jim.


Nov 19 '05 #3

P: n/a
Hello JIM.H.,

There's a great article [1] available that demystifies the web.config file.
I recommend you read it to familiarize yourself with the ideas presented.

To solve your problem: In your web.config...

<appSettings>
<add key="connectionString" value="yourConnectionString" />
</appSettings>

In code, do:

ConfigurationSettings.AppSettings["connectionString"]

[1] http://www.sitepoint.com/article/web...le-demystified

--
Matt Berther
http://www.mattberther.com
Kevin, can you me more clear, where can I store connStr? can you give
example, I am new in asp.net

"Kevin Spencer" wrote:
Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t Timeout=30"))

That's an awfully long name for an appSetting name...

appSettings is a name/value Collection. If you have a Connection
String stored there, you should refer to it by name.

-- HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
Hello,
What is wong with the following code I am getting " The
ConnectionString
property has not been initialized"
Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))
Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub
mySP is a stored procedure wihh is simple "select * from myTable"
Thanks,
Jim.


Nov 19 '05 #4

P: n/a
Hi Jim:

Configuration.AppSettings is used to retrieve a setting from the
web.config file. You pass it a key name, and it returns the value.

It looks like you already have a value for the connection string, so
remove Configuration.AppSettings and look for some ASP.NET and ADO.NET
tutorials to learn more.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Fri, 11 Mar 2005 13:31:06 -0800, JIM.H.
<JI**@discussions.microsoft.com> wrote:
Hello,
What is wong with the following code I am getting The ConnectionString
property has not been initialized

Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings(" Persist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))

Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)

myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConn ection)
DataGrid1.DataBind()
End Sub

mySP is a stored procedure wihh is simple select * from myTable
Thanks,
Jim.


Nov 19 '05 #5

P: n/a
I updated my web.condfig. I got this error:
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
any idea?
"Matt Berther" wrote:
Hello JIM.H.,

There's a great article [1] available that demystifies the web.config file.
I recommend you read it to familiarize yourself with the ideas presented.

To solve your problem: In your web.config...

<appSettings>
<add key="connectionString" value="yourConnectionString" />
</appSettings>

In code, do:

ConfigurationSettings.AppSettings["connectionString"]

[1] http://www.sitepoint.com/article/web...le-demystified

--
Matt Berther
http://www.mattberther.com
Kevin, can you me more clear, where can I store connStr? can you give
example, I am new in asp.net

"Kevin Spencer" wrote:
Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t Timeout=30"))

That's an awfully long name for an appSetting name...

appSettings is a name/value Collection. If you have a Connection
String stored there, you should refer to it by name.

-- HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...

Hello,
What is wong with the following code I am getting " The
ConnectionString
property has not been initialized"
Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))
Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub
mySP is a stored procedure wihh is simple "select * from myTable"
Thanks,
Jim.


Nov 19 '05 #6

P: n/a
thanks for your help. I added user to the database, seems working fine.

"Matt Berther" wrote:
Hello JIM.H.,

There's a great article [1] available that demystifies the web.config file.
I recommend you read it to familiarize yourself with the ideas presented.

To solve your problem: In your web.config...

<appSettings>
<add key="connectionString" value="yourConnectionString" />
</appSettings>

In code, do:

ConfigurationSettings.AppSettings["connectionString"]

[1] http://www.sitepoint.com/article/web...le-demystified

--
Matt Berther
http://www.mattberther.com
Kevin, can you me more clear, where can I store connStr? can you give
example, I am new in asp.net

"Kevin Spencer" wrote:
Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t Timeout=30"))

That's an awfully long name for an appSetting name...

appSettings is a name/value Collection. If you have a Connection
String stored there, you should refer to it by name.

-- HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
"JIM.H." <JI**@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...

Hello,
What is wong with the following code I am getting " The
ConnectionString
property has not been initialized"
Sub BindDataGrid()
Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("P ersist Security
Info=False;Integrated
Security=SSPI;database=myDB;server=MyServer;Connec t
Timeout=30"))
Const strSQL As String = "mySP"
Dim myCommand As New SqlCommand(strSQL, myConnection)
myConnection.Open()
DataGrid1.DataSource =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)
DataGrid1.DataBind()
End Sub
mySP is a stored procedure wihh is simple "select * from myTable"
Thanks,
Jim.


Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.