Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question - SQL Connection

Status
Not open for further replies.

whateveragain

Programmer
Apr 20, 2009
92
US
I found this code at MS's web site to make a SQL connection. I haven't established an on-line web site yet and have been working with What do I put in the System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(" ") command line in order to get this to work?

Thanks

Dim rootWebConfig As System.Configuration.Configuration
rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("What do I put here?")
Dim connString As System.Configuration.ConnectionStringSettings
If (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count) Then
connString = rootWebConfig.ConnectionStrings.ConnectionStrings("MyConnectionString3")
If Not (Nothing = connString.ConnectionString) Then
Console.WriteLine("My connection string = {0}", connString.ConnectionString)
Else
Console.WriteLine("No My connection string")
End If
End If
 
what version of VS and .net framework are you using?

instead of WebConfigurationManager use the static gateway
ConfigurationManager.ConnectionStrings("name of key")

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I'm using 3.5 .net framwork with 2008 SQL and 2008 Visual Studio
 
yeah, I don't know what WebConfigurationManager is. ConfigurationManager.ConnectionStrings() will do fine.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Looks like they changed things in the 3.5 framwork. I am not familar with it yet, but from what I read, you need to put in the web that you want to get the config from..
From the MSDN Example said:
In the following code example, the OpenWebConfiguration method opens and returns the configuration object that corresponds to the Temp Web application in the default Web site, ...
 
string strConnString = ConfigurationManager.ConnectionStrings["name of key from webconfig"].ConnectionString;

in webconfig:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Data Source=myDBServer;database=myDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Ordinary Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top