Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i am using visual studio 2008 and sl server 2008 web application.

in web.config i have given connection string

C#
<connectionStrings>
		<add name="ApplicationServices" connectionString="data source= midas Host;Integrated Security=SSPI;intial catalog=kandivalideal;User Instance=true" providerName="System.Data.SqlClient"/>
	</connectionStrings>



and then i am trying to call the connection string on default page

SqlConnection cnn = new SqlConnection();
        cnn.ConnectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
        cnn.Open(); 
        SqlCommand cmd = new SqlCommand("select mobileno, password from register where mobileno='" + txtmobile.Text + "'and password='" + txtpassword.Text + "'", cnn);
        cmd.Connection = cnn;
        SqlDataReader dr = cmd.ExecuteReader();




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)

can any one tell me what is the issues
Posted
Updated 19-Dec-11 19:50pm
v5
Comments
thatraja 20-Dec-11 0:15am    
Use parametrized query to avoid Sql injection
AmitGajjar 20-Dec-11 0:41am    
you have used wrong Spelling for "Initial Catalog"

thanks
-amit
aayu 20-Dec-11 0:50am    
i have done the changes still it is giving me error
Shobana16 20-Dec-11 2:00am    
Did u try solution5?
aayu 20-Dec-11 2:00am    
yes shobana i did

Try this,
C#

C#
SqlConnection cnn = new SqlConnection();
        string sqlcon = System.Configuration.ConfigurationManager.AppSettings["connString"];
        cnn = new SqlConnection(sqlcon);
        cnn.Open();
        SqlCommand cmd = new SqlCommand("select mobileno, password from register where mobileno='" + txtmobile.Text + "'and password='" + txtpassword.Text + "'", cnn);
        cmd.Connection = cnn;
        SqlDataReader dr = cmd.ExecuteReader();


web.config

HTML
<appsettings>
<add key="connString" value="server=midas Host;database=kandivalideal;" />
</appsettings>
 
Share this answer
 
Comments
aayu 20-Dec-11 3:04am    
no same error i can't able to connect it
Shobana16 20-Dec-11 3:06am    
Please verify the server name and check whether this server is accessible or not..And login try to use sql server authentication.
aayu 20-Dec-11 4:20am    
hmmmm i am checking that only
I think you missed the namespace System.Configuration[^]
 
Share this answer
 
Add a reference to System.Configuration by clicking Project -> Add Reference... and searching through the .NET components for System.Configuration
add namespace System.Configuration.
 
Share this answer
 
Try to put ,,

C#
cnn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
 
Share this answer
 
v2
Comments
aayu 20-Dec-11 0:17am    
It is giving error Keyword not supported: 'intial catalog'.
Shobana16 20-Dec-11 0:58am    
Can you try this , by giving connection string in appsettings?
add namespace System.Configuration.
===================
SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"]);

cnn.Open();

======================

in web.config

<connectionstrings>
<add name="ApplicationServices" connectionstring="data source= midas Host;Integrated Security=SSPI;initial catalog=kandivalideal;User Instance=true" providername="System.Data.SqlClient">

====================

You have written "intial catalog" place of "initial catalog".
initial catalog is a right word.
 
Share this answer
 
Comments
milannaughty 21-Dec-11 1:09am    
Yes. Check it. It will work.
Try this..

C#
<add name="ApplicationServices" connectionstring="server= midas Host;databse=kandivalideal;" providername="System.Data.SqlClient" />
 
Share this answer
 
Try to run visual studio and sql server as administrator
 
Share this answer
 
Please check the spelling of intial It must be Initial.

I hope this will work..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900