Wednesday, March 28, 2012

web.config information

I'm trying to setup my connection to my sql db in my web.config--I did a search and didn't find anything useful --I think b/c the search is still messed up. So I've found some stuff but nothing to really say this is how it's done. Also where does this go in my webconfig --like what section
(DYNAMIC DEBUG COMPILATION--CUSTOM ERROR MESSAGES--AUTHENTICATION --AUTHORIZATION--APPLICATION-LEVEL TRACE LOGGING--SESSION STATE SETTINGS--GLOBALIZATION)
Which I'm sure there are several ways but what I did find was this:
<configuration>
<connectionStrings>
<add name="AppConnectionString1"
connectionString="Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;"
providerName="System.Data.SqlClient" />
</connectionStrings>
<!-- additional settings -->
</configuration>
Now would this be fine, just change my information ? and in my actually app can i just say appconnectionstring1.open? or do I have to do something special. Also I'm drawing my info from my sql DB from a server. So the hundreds of connections that I've drawn up now are created by dragging a sqlconnection control from my toolbox and setting it's connection property to the one designated when I connected through my server explorer. Which way is going to be faster? I just think having all those unecessary sqlconnection controls on my forms is a waste of resources. Any help--any articles would be greatly appreciated.the exact answer to your question is here ... some one asked before and i answered
http://forums.asp.net/1007051/ShowPost.aspx
in the link above you will find the Tab "Starter Kits" this is an open source code form MS and the standard of the code is great...i moslty follwo it ... you can download it and run the code in your machine.... Also the answer in the link above is identical to what you will find there !! Good Luck!!
Thanks, I actaully read that -- and I just wasn't looking at my web.config close enough. Another question though-- do I have to declare the following lines on all my pages though?

Dim myConnAs SqlConnection
myConn =New SqlConnection(ConfigurationSettings.AppSettings("connString"))
Or can I put this somewhere too? I've noticed though since I created my sqlcommand's and what not that I have to put sqlcommand1.connection = myconn so it will recognize that a conneciton is open.


another question do I have to set the connection for the sqldataadapter's select, insert, update, and delete commands seperately?

onewisehobbit wrote:

Thanks, I actaully read that -- and I just wasn't looking at my web.config close enough. Another question though-- do I have to declare the following lines on all my pages though?

Dim myConnAs SqlConnection
myConn =New SqlConnection(ConfigurationSettings.AppSettings("connString"))
Or can I put this somewhere too? I've noticed though since I created my sqlcommand's and what not that I have to put sqlcommand1.connection = myconn so it will recognize that a conneciton is open.


the configurationSetting(....) is basically calling the connString ...and as you can see you dim the connection in the method so that means you need to call it in each method you need need to connect to DB

onewisehobbit wrote:

another question do I have to set the connection for the sqldataadapter's select, insert, update, and delete commands seperately?


what you mean by this ?? but i understand what you mean
Dim con as new SqlConnection(....)
"con" will be used in the commands to represent the connection string

I meant something like this:
SqlDataAdapter1.SelectCommand.Connection = myConn
SqlDataAdapter1.InsertCommand.Connection = myConn
SqlDataAdapter1.DeleteCommand.Connection = myConn
SqlDataAdapter1.UpdateCommand.Connection = myConn
I've put this in my page_load event--is it safe to say that this can go in the If not page.ispostback or should I let the lines fire everytime in the page_load event?
Also my other question I guess I didn't word it totally the way I should have. I am pretty sure I'd have to declare the following on every page:
myConn =New SqlConnection(ConfigurationSettings.AppSettings("connString"))
I was wondering though if it's possible to put the Dim myConn=SqlConnection somewhere in my project so that I won't have to keep declaring it?
Again thanks for all the help it's greatly appreciated.


onewisehobbit wrote:


I was wondering though if it's possible to put the Dim myConn=SqlConnection somewhere in my project so that I won't have to keep declaring it?
Again thanks for all the help it's greatly appreciated.


well if you have it a public on the class BUT...... i did not see anyone did that as a programming technique.... ican not lie to you by saying Yes or No but i always declraed in method that i need to call the connection object !!!!! i hopw some one with better experience to rescure me and answer about this point ...but personally i did not see anyone did it and i did not try it !!!!

0 comments:

Post a Comment