C# - Use Connectionstring From Web.config In Source Code File?

Mar 15, 2011

I know this might be a very basic question, but maybe thats why im having problems finding the answer. Right now I'm creating database connections in my source files by doing something like this:

SqlConnection con = new SqlConnection("Data Source=...Password=...);
SqlCommand cmd = new SqlCommand(String.Format("SELECT * FROM Table;"), con);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();

But this means that if I choose to change databases it will be a major pain in the ass. Do you guys know how to use the connection string from a web.config file instead?

View 5 Replies


Similar Messages:

Configuration :: ConnectionString With Data Source In Web.Config?

Mar 10, 2010

<configuration>
<add
name="stringname"

[code]...

View 9 Replies

Configuration :: ConnectionString And Config File?

Feb 4, 2011

how can i encrpt database password and store to Visual Studio's connectionString areaalso, i would like to know how can i set all config in config file and how the program can read.

View 2 Replies

DataSource Controls :: Encrypted Connectionstring And Store At Web.config File?

Jan 19, 2011

I encrypted my connectionstring and store at web.config file. Then I bind Gridview with sqldatasource control, cannot bind because of sqldatasource don't know the(encrypted) connectionstring.

View 5 Replies

Configuration :: Error 1 Could Not Open Source File: Could Not Find File 'C:11-22 EstobjDebugCSAutoParameterize RansformedWeb.config'. 0 0 Test

Nov 24, 2010

I have built an ASP.NET (.NET v4) application in VS 2010. It is working just fine. But when I try to create deployment package (so I can deploy it in our test IIS 7.5 Server), it gives me error like this,

Error 1 Could not open Source file: Could not find file 'C:11-2 estobjDebugCSAutoParameterize ransformedWeb.config'. 0 0 test

Thing is in past, I had deployed the SAME application using the SAME method.

View 2 Replies

ADO.NET :: How To Use Connectionstring From Web.config

Jan 2, 2011

I have a connectionstring in my web.config <add name="HeimkinoVerbindungszeichenfolge1" connectionString="Data Source=SERVER;Initial Catalog=Heimkino;Persist Security Info=True;User ID=sa;Password=*******;"providerName="System.Data.SqlClient" />

This itself is working when using eg the SQLDataSource for a Gridview or similar.

Now I need to access this DB with different scripts and work with that database.

Eg I need to run this comand in a page_load against the DB

[Code]....

to remove old events from the database

For other pages I need something like

[Code]....

for some userauthentication things this should just create a recordset I can work with then.

Is there a way to realize this using the connectionstring in the web.config (and if so, How???)

If this will not work, how can I run such queries?

View 10 Replies

How To Protect The Connectionstring In Web.config

Oct 26, 2010

I have a website about to go live. I'm wondering what I should be doing about the connectionstring in the web.config. Do I obfuscate it and it so how?

View 3 Replies

C# - ConnectionString From App.config Of A DLL Is Null

Sep 4, 2010

I have a class library that contains a valid connectionString inside the app.config. Inside that class library I want to use it with

ConfigurationManager.ConnectionStrings["NAME"].ConnectionString

My ASP.net 4.0 framework application references that DDL and retrieves data from it. I want create a Entity Framework 4 DataContext within my DDL with the ConnectionString from the App.config. (I do not want to pass the connectionString from my ASP.net application in every single method. (I'm using ObjectDataSources))

However, this line inside my DLL throws a NullReferenceException.

ConfigurationManager.ConnectionStrings["NAME"].ConnectionString

View 2 Replies

C# - Dynamically Change ConnectionString In Web.config?

Aug 9, 2010

I have the following in my web.config

<connectionStrings>
<add name="ActiveDirectoryConnection" connectionString="LDAP://ActiveDirectoryDomain1.com" providerName="System.Web.Security.ActiveDirectoryMembershipProvider"/>
</connectionStrings>

I need to add a dropdown box to my login page that allows the user to change the connectionString to a different string, e.g. "LDAP://ActiveDirectoryDomain2.com"

In C# code behind how do change the connectionString value?

More info:

The problem I am having is that there are 4 other web.config settings call that one connectionString. For example:

<activeDirectorySecurityContextSettings connectionStringName="ActiveDirectoryConnection" defaultADUserName="ReportUser" defaultADPassword="password"/>

View 3 Replies

Configuration :: Get All Connectionstring Defined In Web.config?

Mar 7, 2011

i want to get all connectionstring defined in web.config

var dk = System.Configuration.ConfigurationManager.ConnectionStrings;

problem .i am define 2 connectionstrings in web.config but upper code return me 3 connectionstring

dk[0] = LocalSqlServer (dont know where to come )

dk[1] = connection1 (Define by me )

dk[2] = connection2 (Define by me )

so how i can get only 2 connection from Web.config

View 6 Replies

SQL Server :: Define And Read ConnectionString From Web.Config?

Dec 17, 2010

I am new to asp.net and wondering if anybody can help me defining SQL Server 2005 ConnectionString in web.config file and call/read anywhere in application on any button.Kindly provide me code example.

View 3 Replies

WebMatrix :: Use Database.Open For ConnectionString From Web.config?

Aug 12, 2010

As mentioned in this tutorial (http://www.asp.net/webmatrix/tutorials/5-working-with-data), I tried using my own connectionstring from web.config.

I got this error: "Format of the initialization string does not conform to specification starting at index 0."

The tutorial suggests to use: Database.OpenConnectionString("SmallBakeryConnectionString") method

Instead you should use Database.Open("ConnectionStringName").

Ref: http://cytanium.com/forums/yaf_postsm18_Connection-string-problem.aspx

The API Document is missing Database.Open method and also Database.OpenConnectionString info needs to be modified.

View 7 Replies

DataSource Controls :: Set Up Connectionstring At Runtime From Web.config - MySQL?

Jul 7, 2010

I want to setup the connectionstring of the SqlDatasource of a dropdown list at runtime, eg. Page Load event. I have install MySQl ODBC driver, System DSN name as "MySQL_Employee" If I have an entry in Web.config:

<connectionStrings>
<add name="mysqlConnection" connectionString="DSN=MySQL_Employee;UID=john;description=connection to employee database;server=empServer;database=employee;port=3306;" providerName="System.Data.Odbc"/>
</connectionStrings>

View 1 Replies

C# - How To Extract Classes' Source Code From A Dll File

Jan 16, 2011

Is there any software for the same? I didn't find any useful information on the internet so asking here.

View 4 Replies

Forms Data Controls :: Creating A SQL Connectionstring For The Web Config And Textsearches?

Jul 24, 2010

am having problems creating this;1. How to create a add a connectionstring to my web config fileThis is the connection string I have entered

Datasource=.SQLWEXPRESS; attachDb filename=c:inetpubwwwrootdevelopment_ecommerceApp dataextratime.mdf;integrated security=true; user instance true

I have tried to enter this as well

<connectionStrings>
<add name="development_Ecommerce" connectionString="Data Source=smbc-652263fbfaSQLEXPRESS;Inital Catalogue=extratime; Integrated Security=True" providerName="System.Data.SqlClient"/>

[code]...

View 3 Replies

Convert Vb File To Dll Or Encode(encrypt) Vb Source Code?

Dec 24, 2010

Is there anyway I can encode my asp.net source code?

I really don't want my customer to steal my vb source code. They refused to pay extra for the source code and license. So we need to convert vb file to dll or encode(encrypt) vb source code that no one can understand the logic or decode(decrypt).

I'm using VS 2010 and .Net 4.0 Framework.

View 4 Replies

How To View Source Code Of Dll File In Visual Studio 2010

Nov 28, 2010

how to view source code of dll file in visual studio 2010

View 3 Replies

Visual Studio :: Source Code To Display On One Line Instead Of Multiple In Source View?

Nov 1, 2010

how to make my source code to display on one line instead of multiple in source view. The display drives me batty when I'm trying to find something and I would prefer to display across the page instead of multiple lines down the page.

View 2 Replies

Open Source Lead Management System With Source Code?

Sep 6, 2010

asp.net open source Lead management system with source code.

View 9 Replies

Create A Connectionstring For Code Project?

Apr 5, 2010

i have some websites and one part of all websites is the same and it work with dataset i got an ide to creat a code projrct to handel that part and i use it in all websites the problem is the websites not use the same connectionstring but the connectionstring name can be same. i need to set this code project to read the connectiostring from the website web.config file.

View 6 Replies

C# - In EF4.1 Code First - Override ConnectionString Name In Web.configuration?

Mar 23, 2011

I'm creating a multi-tenant Asp.Net MVC 3 Web app, and using EF4.1 code first for the db model.For development I'm happy to use SqlServerCE in App_Data, and for production this will move to Sql Server 2008.

Say my context is called "MyModels", by default code-first looks for a connection string called "MyModels" in Web.config. This can be told to use a file in App_Data or changed to access a database in SQL2008. All fine so far.

But because of multi-tenancy, I'd like the SqlServerCE filename to match the unique id of the tenant (so App_Data would have "client_x.sdf", "client_y.sdf"; Sql Server 2008 would have separate databases). I can't work out how to direct to these different databases.

I've tried MyModels inheriting from DbContext and supplying a connection string (using a 'placeholder' conn string in Web.config and replacing "{clientId}" with the unique id), and I've also tried setting the connection string in the MyModels constructor:

base.Database.Connection.ConnectionString = xxx;


but this never seems to work. I always get the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

( it's not yet 'configured' to use SqlServerCE, and so is trying to connect to Sql Server)

Tracing the code, Database.Connection.ConnectionString hasn't been read from Web.config at this point, so I can't search and replace that, and, possibly, it's getting overwritten by the 'placeholder' conn string later in the pipeline.I reckon this must be quite straightforward and I just can't find the 'hook'.

View 2 Replies

DataSource Controls :: Set ConnectionString From Code?

Sep 13, 2010

I have 2 connection strings in my web.config file, and I would like to select which one to use, from code.Currently I have this:

asp:SqlDataSource
ID="SqlDataSourceDelegateServices"
runat="server"

[code]...

View 3 Replies

Web Forms :: Declare Url In Web.config File And Give Them A Name And Access From Vb.net Code Behind?

Mar 1, 2011

I have a project that has 4 pages and from each page have several link buttons to go each of the other pages. I would like to declare these url in the web.config file and give them a name and access from vb.net code behind.

View 3 Replies

Configuration :: How To Merge A Distribution Web.config File And An Existing Web.config File

Mar 30, 2010

I'm preparing to deploy a ASP.NET web application. The target server has already a previous version of my web application with parameters specified on the web.config file.

In the new version of this web application, the web.config file contains new sections I would like they appear into the target web.config file on the server.

However I can't find the way to merge the new web.config sections into the existing web.config file ?

Does I have to do it programmatically, or is there a tool to merge the both files during installation ? (I'm using Web Setup Project).

View 2 Replies

Configuration :: How To Call The "host"setting From The App.config File In C# Code

Mar 17, 2011

<configuration>
<system.net>
<mailSettings>
<smtp
from="user@user.com">
<network
host="smtp.server.com"
password="password"
userName="username" />
</smtp>
</mailSettings>
</system.net>
</configuration>

How can I call the "host"setting from the App.config file in my C# code?

I have tried this but it does not work.

SmtpClient mailClient =
new SmtpClient(ConfigurationManager.AppSettings["network"]);

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved