Dear Experts,

I am new in asp.net.
I have to make a website in asp within 5 months. I have written connection string for sql server 2008 R2.
I want to use "default login" but my connection string does not work.

    <connectionStrings>
   <add name="donationConnectionString" connectionString="Data Source=COMPAQ-PC\SQLEXPRESS;Initial Catalog=donation;Integrated Security=True"
   providerName="System.Data.SqlClient" />
 </connectionStrings>

And I have created connection on every page. But my connection is not created.

using system.data.sqlclient;

sqlconnection con = new sqlconnection("Data Source=$$$$; Initial Catalog = $$$$$; Integrated Security=true");

con.open();

I need your help. . . .

If you add a connection string to the web.config and intend to use it, you access it with this:

sqlConnection con = new sqlConnection(ConfigurationManager.ConnectionString["donationConnectionString"]);

You will need to add System.Configuration to your using statements at the top of the class for this to work. The configurationManager will then go to the web.config file and get the connection string named "donationConnectionString".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.