Q: connection problem

G

Guest

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;Connect
Timeout=30"))

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

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

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

Kevin Spencer

Could be the following:

Dim myConnection As New
SqlConnection(ConfigurationSettings.AppSettings("Persist Security
Info=False;Integrated Security=SSPI;database=myDB;server=MyServer;Connect
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.
 
G

Guest

Kevin, can you me more clear, where can I store connStr? can you give
example, I am new in asp.net
 
M

Matt Berther

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-config-file-demystified
 
S

Scott Allen

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.
 
G

Guest

I updated my web.condfig. I got this error:
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
any idea?


Matt Berther said:
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-config-file-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
 
G

Guest

thanks for your help. I added user to the database, seems working fine.

Matt Berther said:
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-config-file-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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top