How to create a connection to a sql Database from a database class?

Hello Mate!,

                I have a Database clss and a web form I have just mentioned in the Web config file of the webform for connection string as

  <add name ="SQL" connectionString="Server=Servername;Database=mydatabase;uid=some user id ;pwd=some password;"/>
 </connectionStrings >

and i have just mentioned in a class in which i want to create a connection to the Db when ever i create instance of that class

i have just coded as below in that class(Database Class)

   public class Database

        string Conn_String;

        public Database()
            Conn_String = ConfigurationManager.ConnectionStrings("SQL").ConnectionString;


But it gives an Error as "System.Configuration.ConfigurationManager.Connectionstring"is a property but it is used like a method!.

Whats wrong with my code?. I have just  mentioned in the Constructor of the database class to create a connection whenever an instance of this class is created!.

How to Solve this?

Could you please help me on this?

Much Obliged & Thanks a Lot,
8/4/2008 4:24:00 AM 93655 articles. 6 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 43

 You are using VB syntax here to access the ConnectionStrings collection. In C#, you should use [ and ] (square brackets) instead. Change your code to:

 Conn_String = ConfigurationManager.ConnectionStrings["SQL"].ConnectionString

If this post was useful to you, please mark it as answer. Thank you!
8/4/2008 6:35:09 AM

Thank You Very Much!,

Much Obliged & Thanks a Lot,
8/4/2008 6:39:44 AM

Similar Artilces:

How to create a single Oracle Database connection method or function to be used on or by all classes and pages that want to connect to the database?
 How to create a single Oracle Database connection method or function  to be used on or by all classes and pages that want to connect to the database? How can I create one method or function in csharp to be used on all pages or classes when conenction to the database? Please give an example.I have database connections which I am using on each and very page or classes, but I can I put in one page then I just start  calling it?Database connection I am using:   OracleConnection dbconnection;    this.dbconnection = new System.Data.OracleClient.OracleConnec...

How to connect a sql database to a web form.
I am reletivaly new to .net programming. In your HTML; <body> <form id="Form1" method="get" runat="server"> <asp:DataGrid ID="myData" AutoGenerateColumns="True" Runat="server" /> </form> </body> In your code-behind page; protected System.Web.UI.WebControls.DataGrid myData; private void Page_Load(object sender, System.EventArgs e) { SqlConnection con = new SqlConnection("server=yourserver;database=NorthWind;uid=sa;pwd=;"); SqlDataAdapter da = new SqlDataAdapter("select * from employees", con); DataSet ds = new DataSet(); da.Fill(d...

How can I change my connection to a different is not connecting to the database I created.
My data is connected to the ASPNETDB.MDF database. Is this a must that I have it connected to this database or can I have it connected to a database that I created. You can connect to different database such as sql or other access files. All you have to do is to define which connection string to use within your web.config file. If you want to make sure that your database is prepared to be used, use features such as ASPNET_REGSQL.EXE at VS Command Prompt. Hope this helps. I'm in the in Georgia. Is it cold there.. Hi Jae,    &nb...

Adding Create database user, Create database and Create Administrator UI Dialogs in Web Deployment Project
Hi guys,Are any of you adept at creating these UI dialogs for their web deployment projects? I need to be able to create a new user, create a new connectionstring, run a DB build script, and create an administrator account during the web deployment process.I must also be able to edit some settings with IIS.How do you go about doing these in VS2005 Web Deployment Projects? I know I can add new dialogs for the install process, but don't know what to do next.Thanks!

CREATE DATABASE permission denied in database 'master'. Error while connecting to SQL Express edition
CREATE DATABASE permission denied in database 'master'.An attempt to attach an auto-named database for file C:\Domains\\wwwroot\App_Data\personal.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share. This is the error we get while connecting to the SQLExpress server. Any suggestions, hint, etc. would helpThanksSnehal Rana  The error message is saying that the database is already attached.  Since you are using iis instead of the built in web host you are going to have to go into IIS manager an...

Create a web form that'll add a record to an SQL database
Hi everybody, I am new to ASP.NET and am wanting to start creating some member sites and user content submission sites, and am trying to learn as quickly as I can by using MS Visual Web Developer 2005 Express Edition. I have created a member area and create users pages and such, but am now wanting to allow a user to submit an article to the website which can include formatted text, images and sample code (its a programming article site), firstly, what is the easiest way to do this because I thought about submitting each article as a record in an sql database but that wouldnt provide me with ...

How to create SQL Mobile 2005 database from a MS SQL 2005 database?
Hi guys,I'm trying to find solutions to help me in creating a SQL Mobile 2005 database from a SQL 2005 database, with the same table structure and data.May I know how can I achieve this?Thanks.Regards,Jenson Hi Jenson, Visual Studio 2005 or SQL Server 2005 is able to open SQL Mobile 2005 database. However you need either SQL or .NET code to convert SQL Mobile 2005 database this way. Here is an example from MSDN forums which is to convert to xls instead: Ji MaSincerely,Microsoft Online Community Suppo...

How do I create a custom MembershipProvider class to connect the Login controls to point to a different SQL database?
Hi all, I am new to Visual Studio 2008 and am struggling to create a login control that uses my own username, password and usertype database that I created in an sql table. I would like to be able to change the Login button to check what type of user it is logging in so it brings up the right part of the site eg: Admin is brought to the website admin section of the site but all other users are brought to the logged in user area. Through research I found that it is the way the MembershipProvider is declared in the web.config file. I guess what I am looking for is a step by step guide...

Please help, I can't create a connection between my web page and database in MS-Access/Sql-Server
Hi all , Recently I was trying to establish a connection between my web page and the database made in MS-Access/SQL-server. But all my efforts were in vain at last. Please help me to do this. Write all the steps. Looking for a perfect solution.  Thanking,Kristian  Which is it? Access or SQL Server?  Here's a tutorial for Access: Connection stirngs for all types of database can be found here:  Regards Mike [MVP - ASP/ASP.NET]My site hopefully u are us...

Submitting Web forms fields to sql database by clicking on SUBMIT FORM and sending the form fields to email box
I have a created or designed a form to be stored in a SQL database table and at the same time when a user clicks on SUBMIT button the form fields will automatically goto the visitor email address immediately. Also i have created a database with tables for each of this forms Pls help i have over 10 forms designed but the problem of submitting them to the table database and the user email address is the challenge now.... You ned to familiarise yourself with the basics of database access in ASP.NET.  There are free tutuorials here:

New errors access MS SQL Server Database on (CREATE DATABASE and Batch SQL Statement)
------=_NextPart_000_002B_01C2F2CB.0C201FF0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I'm running ActiveState perl 5.8.0 on a WIN2K box with MS SQL Server = 2000. Recently I updated DBD-ODBC to v1.05 and DBI to v1.35 Now I get the following errors executing some sql commands CREATE SQLSTMT:[CREATE DATABASE POMS_SER ON (NAME =3D 'POMS_SER_DAT', = FILENAME =3D 'd:\Database\POMS\POMS_SER_Data.MDF', SIZE =3D 10MB) LOG ON = ( NAME =3D 'POMS_SER_LOG', FILENAME =3D = 'd:\Database\POMS\POMS_S...

SQL Attached mdf database files VS database imported into or created in SQL Server 2005
 Hi all (newbie @ @ ASP 3)What is the purpose of using an attached MDF database files in the App_Data folder on a web site as to importing it into the SQL server directly or creating it on the SQL server. Does a mdf database attached file purely use the SQL server as a connection interface.Is it something similiar to DSN(ODBC) Connections for ms access databases. AFAIK it is only for deployment conveniance, I have always imported the database directly into SQL Server and set up the connection string accordingly.Don't forget to click "Mark as Answer" on the...

Database Connection???How to connect a Database in an other server?
How to connect a Database(.mdb) in an other server? Can I use the connection string like below? mycon.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=http://www.****.com/***/mydb.mdb" You can not. That simple. Access is file based. No a client/server architecture.Thomas TomiczekPowerNodes ApS(Microsoft MVP C#/.NET)---Building a Website? Try the PowerNodes CMS - Correction: you can. Just make sure you can reach the acces db file - through a file share that is bound as drive. Not that you should. Performance will be horrib...

Web Form to SQL Database
Hi all, I am very new to ASP.NET, Can someone please help me out on this matter. I simply need a brief example on how to insert textbox values, from a web form to an SQL database.  Any ideas? Hello tomcarbonese, t> Hi all, I am very new to ASP.NET, Can someone please help me out on t> this matter. I simply need a brief example on how to insert textbox t> values, from a web form to an SQL database. Read there detailed description Nemtsev | Microsoft MVP [.NET/C#] | .Net Tips & Tricks Publication It's ...

Web resources about - How to create a connection to a sql Database from a database class? -

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video -
If you send more email, you might make more money. Then again, you might destroy your reputation and revenue stream. Here's how to know what ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

MOTHER’S DAY: Facebook Examines Connections Between Moms, Kids
With Mother’s Day on the calendar this coming Sunday, Facebook examined the relationships between mothers and their children on the social network, ...

Kings Cross identities arrested in connection with murder
Two Kings Cross identities&nbsp;have been arrested in connection with the murder of a man at Sydney hotel.

Governor declares state of emergency in connection with California methane leak
... of Emergency Services) On Wednesday evening, California Governor Jerry Brown declared a state of emergency in Los Angeles County in connection ...

Miss Golden Globe role 
requires showbiz connections
One constant about the Golden Globes (tonight at 8 on WHDH, Ch.

Tons Of Methane Are Spewing Out Of California, And There’s A Connection To The Governor
The out of control leak has forced thousands of residents to flee their homes. Gov. Brown's sister is a paid board member at the company that ...

Toyota and Kymeta rely on satellites to power this Mirai's data connection
They're hoping to achieve gigabit wireless speeds within the next few years.

Test Claims To Show T-Mobile’s YouTube “Optimization” Is Just Connection Throttling
... on the same network, and at the same time of day. They tested video streaming against three other kinds of downloads and measured the connection ...

Resources last updated: 1/13/2016 10:24:34 PM