How do I use my web.config connection string in my DataAdapter/Connection that I created with drag/drop and data binding

This is a little hard to put into words...

I have a form with a number of textbox fields on it that are bound to a data adapter. The data adapter and it's sql connection were created by dragging the objects onto the screen from the toolbox (not in code). I open connections in other places and use my connection string in web.config for those. The on-screen sql connection object doesn't seem to allow me to just fill in the function that pulls my conn string from web.config so in page.load, I set it's connection string to my connection string.
Does the page load fire before the connection object will try to use the "design time" connection string, or am I taking a performance hit while it tries to connect using the original (possibly invalid) string before page load fires?
Should I just create the adapter/connection in code and remove those "visual" objects? Will that affect my databinding that I currently have set up? Is there a way to make the connection object I have there already pull my string from web.config instead of requiring me to type a literal string in it's property?
Thanks
0
KenP2600
5/21/2004 3:50:53 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

3 Replies
810 Views

Similar Articles

[PageSpeed] 49

I very rarely, if ever, use the drag-and-drop adapters, but I believe that the adapter you added will not even connect to the database until you write the code to tell it to (the sqlDataAdapter.Fill() method.)  Page_Load happens after the component initialization, so by changing the connection string there you should be able to override the predetermined string.
0
BurntSky
5/21/2004 3:59:48 PM
Hi,

I'm not quite sure what you have played around but you surely sound like you need something like this in your web.config file outside your <system.web> tag
<appSettings>
<add key="ConnectString" value="Server=(local);Database=NorthWind;uid=sa;pwd=sa"/>
</appSettings>
Than in your application code, you could get to this value using something like this.
string strConn = ConfigurationSettings.AppSettings.Get("ConnectString");
I hope this helps and please do reply if it worked or you are looking for somemore than this.
Regards,

Shravan Addaypally MCP

0
shravan79
5/21/2004 4:15:04 PM
Shraven, I'm already using that method to get my connect string, I was just working on getting my "drag and drop" data adapters to use that string as well.

BurntSky, if it doesn't go out and look for the database until I call Fill, then it sounds like what I'm doing in Page.Load will work fine.
I may eventually go ahead and pull those adapters and add code for them as well, but since I was using those databound text boxes, it was nice to have them there so I could just select my field names from the list, etc.
If anyone has a reason I shouldn't be doing it as I've described, let me know. Otherwise, this gives me easy databinding of my textboxes on my dev machine, and my code can point it to the production db when it runs.
Thanks for the replies.
0
KenP2600
5/21/2004 4:55:42 PM
Reply:

Similar Artilces:

Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application
 Why we use Web.Config File for connection string wether we can use class Library for get connection for whole web Application  please help me? Friend, Web.config has its own advantages. 1) Web.Config is used to store the important information like connections strings etc...so that it can be modified even after the code has been    deployed to the server without compiling the entire application again. 2) Since it is a XML file, there is no need of building the project of you are going to change the connection strings.   If you go for the class files,...

Get connection string from web.config and secure that connection
Hi, I store my connection string on my web.config file, and I want to create a new connection on c# like:SqlConnection con = new SqlConnection();con.ConnectionString= //connection string on web.config fileAfter that, The connection string on the web.config file is in clear text and I want to make it secure but easy to work because this job is to deliver until friday. Is there any easy way to do this and keep the possibility of creating a new connection and making reference to this connection string without need for decrypt data?Thanks, please help!Best regards,David Ribeiro After reading t...

OLEDB Connection problem using Connect String from Web.config
Hi,Cananybody tell me why I am getting the following error for the following code below An OLE DB Provider was not specified in the ConnectionString.  An example would be, 'Provider=SQLOLEDB;'. "Ppp" is a connection defined in Web.config which works with SqlDatasource in the application. DataSet RunQuery(String QueryString) { String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Ppp"].ConnectionString; OleDbConnection DBConnection = new OleDbConnection( ConnectionString); OleDbDataAdapter DBAdapter; DataSet ResultsDataSet = new DataSet(); M....

Object Data Source +Change Connection String without using Web.Config
Hi everyone!   I have setup an ASP.NET application with uses ObjectDataSource's with TableAdapters which map to an SQL server.  Now, when I move it over to our development, then production servers, I don't want to have to change the web.config file each time.  We are not depoying the application, just "copying" it over right now.  That throws off my Beyond Compare sync when the web config files are different.  I have found a way to modify the ObjectDataSource's connection using an ObjectCreated event handler, but then again, I would rather not do that either.  ...

app.config connection string not being read
I have a Web app that has a UI Website Project and a DB dataset/db project. I am running SQL Server 2005 Express on my localhost for development purposes. I have the connectionstring for the DB in the DB projects app.config. The site is running perfectly on my localhost, but when I deploy the site to the review server and change the app.config's connectionstring accordingly a connection to the DB cannot be established. I then tried changing all the db names, usernames, password to jibberish in my app.config file on my localhost and running AND THE SITE STILL RAN ON LOCALHOST. For so...

web.config having multilple connection string name with same connection.
Issue 1:   <add name="Conn1" connectionString="Data Source= SID;User Id=UN;Password=Pwd" providerName="Oracle.DataAccess.Client"/>  And use Conn1(Read and Write from DB)  All over the application. (for exam: all Data Access Layer). VersusIssue 2: <add name="Conn1" connectionString="Data Source= SID;User Id=UN;Password=Pwd" providerName="Oracle.DataAccess.Client"/> <add name="Conn2" connectionString="Data Source= SID ;User Id=UN;Password=Pwd" providerName="Or...

HOW TO USE THE CONNECTION STRING IN WEB.CONFIG
I have a connection string defined in the web.config file and as you know it is given a name.How can I reference such a connection string from a web form using the name given in the web.config file?What I actually do is to copy and paste the whole string in my web forms as follows:Dim pgConn As New PgSqlConnection("User Id=postgres;Password=p@ssw0rd;Host=localhost;Database=e-restdelivery;Persist Security Info=True;Schema=restaurant;Protocol=2")This method is not efficient because if the string changes I have to modify every web form where a connection string is locat...

Using a connection string from web.config
Ok. I thought this was going to be easy but it is turring out to be harder than I expected. I want to use a database connection string from the web.config file. If I use a sqldataadapter and configure a connection then the page works fine. If i attempt to use the information from the web.config file I get the following message when attempting to connect to the DB. The ConnectionString property has not been initialized. Here is the code that I am using to establish the connection. Imports System.Web.Security Imports System.Data.SqlClient Public Class WebForm1 ...

how to get the connection string from the web.config?
how do i get a connection string from the web.config file? I keep getting Error Reading the database.Instance failure.   when i use string connectionString = WebConfigurationManager.ConnectionStrings["conString"].ConnectionString;   but this same connectiong string works when i hard code it into the string variable....   Thankspwpaust http://forums.asp.net/thread/1374383.aspx Have a look at this thread. Hi   I read that link, thanks but it still didn't work..here is the code... <configuration> <appSettings/>  <connectionStrings&g...

How to use Connection String from Web Config
Hi All, How do I use the Web Config connection string in code behind? What is the syntax Dim oCnn As New SqlConnection= ???? Thanks    Dim oCnn As New SqlConnectionoCnn.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionStringDont forget to import System.Configuration Regards Mike [MVP - ASP/ASP.NET]My site...

How to create connection string in web.config files
Hi, I designing web site using asp.net c#, breafly explain me how to create connection string in web.config file and how to call that string in inside the class declration as public variable or strictly we have to call in page load event only.. give lines of code for understanding...I wish you goodluck Easiest way to create connectiong string is to drag and drop one of your tables from the database to the page - connection string will be generated automatically. And you can call it like this:string conString = ConfigurationManager.ConnectionStrings["ConnectionStringName"]...

How to use the connection string from the web.config with a method?
I have been trying to create the connection and then pass it around with no luck. Instead I've been able to just keep recreating it with each method on the page. I don't know why when I create a variable in the page_load event it just doesn't get seen inside of methods. If I put the variable holding the connection string in the page before the page_load event, I think the page class?, it still doesn't work. Could someone give me a heads up on why please? THank you so much in advance.  1 using System;2 using System.Data;3 using System.Configuration;4 usin...

Trying to use web.config for connection strings
I am trying to use a web.config file to store my connection string for my web app, but I am unable to retrieve the stored values, here is the code to my web.config and the sample page I'm testing. Sample Page dim strSql as string dim ds as dataset dim da as oledbDataAdapter dim Conn as string dim myconn as oledbConnection sub page_load(Sender As Object, E As EventArgs) lblDate.text = "Today's Date is: " & date.now.tostring() GridLoad() End sub Public sub GridLoad() strSql = &qu...

Getting a Connection String from my Web Config file
Is there a way that I can create a class or a generally available function in Visual Web Developer Express that will return the connection string that I stored in the Web config file and/or a new connection based on that string?Any help appreciated.Regards,Roger Swetnam  in the Class where all Data Base logic is implementd define a Method like this: public string GetConnectionString(string stringName) { return ConfigurationManager.ConnectionStrings[stringName].ConnectionString; }  where stringName is the Name of your desired Connection string. its a Generic...

Web resources about - How do I use my web.config connection string in my DataAdapter/Connection that I created with drag/drop and data binding - asp.net.getting-started

Microsoft Data Access Components - Wikipedia, the free encyclopedia
This article has an unclear citation style . The references used may be made clearer with a different or consistent style of citation , footnoting ...

BlueVision, LLC - .NET Tips and Tricks
Note: Some tips might become outdated as new versions of the associated products are released. Debugging the OnStart method of a Windows Service ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

DotNetNuke – Data Access Layer Alternative
-*+Now that I’ve explained the standard way of creating a Data Access Layer (DAL) for DotNetNuke, we can address the alternative method of providing ...

MSDN Magazine December 2001
The Windows XP kernel includes a number of improvements over Windows 2000 that promote better scalability and overall performance. This article ...

Visionpace :: Software Development in pace with your vision
Software development, coaching and training using Agile methodology and Microsoft technologies

accounting software using visual basic and c#
developing accounting software using visual basic and C#

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Latest Updates
Latest Updates - Free source code and tutorials for Software developers and Architects.; Updated: 15 Feb 2013

Resources last updated: 1/23/2016 6:49:29 AM