Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have this connection string on c#
C#
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

in web config

C#
<connectionStrings>
   <add name="bongahConnectionString" connectionString="Data Source=./SqlExpress; Initial Catalog=bongah;User Id=x; Password=x"
     providerName="System.Data.SqlClient"/>


How can solve this problem
please help
Posted
Updated 10-Jan-14 5:21am
v2
Comments
Ron Beyer 10-Jan-14 11:23am    
What version of ASP.NET are you using? 2 or 4?
m-e-h-d-h-i 10-Jan-14 11:26am    
4

Um.
Data Source=./SqlExpress;Initial Catalog=bongah;User Id=my user id; Password:my password
                                                                         ---^
Are you sure that should be a colon?
Try:
Data Source=./SqlExpress;Initial Catalog=bongah;User Id=my user id; Password=my password



"i had update question"

One thing springs to mind:
C#
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
This reads a string called "ConnectionString" from the web.config file.
HTML
<connectionStrings>
   <add name="bongahConnectionString"
        connectionString="Data Source=./SqlExpress; Initial Catalog=bongah;User Id=x; Password=x"
        providerName="System.Data.SqlClient"/>
This defines a string called "bongahConnectionString" in the web.config file. The two names should match.
Do you also have one called "ConnectionString" that might be confusing the issue?
 
Share this answer
 
v2
Comments
Ron Beyer 10-Jan-14 11:03am    
+5
Mike Meinz 10-Jan-14 11:08am    
+5
And it also looks like there is an extra quote after my password in the add name= value part.
OriginalGriff 10-Jan-14 11:41am    
No, the ProviderName is a separate config string attribute:
http://msdn.microsoft.com/en-US/library/htw9h4z3(v=VS.80).aspx
m-e-h-d-h-i 10-Jan-14 11:09am    
thank you for your attention but this is syntax error when i did writing codes in codeproject
error still apear
OriginalGriff 10-Jan-14 11:15am    
So copy and paste your exact data - don't try and type it in - just replace your username and password with 'X's after you paste it in.
XML
"Data Source=./SqlExpress;


Should be:

XML
"Data Source=.\SqlExpress;
 
Share this answer
 
Comments
m-e-h-d-h-i 10-Jan-14 11:39am    
another error
Login failed for user 'x'.
Ron Beyer 10-Jan-14 11:41am    
Is it really 'x' or are you just omitting the actual user name? Did you check to see that the SQL server permissions allow that user to log in?
OriginalGriff 10-Jan-14 11:53am    
Redacted at my suggestion to prevent him publishing his login details when he pasted the "real" data
Ron Beyer 10-Jan-14 11:59am    
Level 1 tech support exists for a reason :) Sometimes the obvious needs to be asked!
OriginalGriff 10-Jan-14 12:19pm    
"Is it plugged in?"
"Do you have a power cut? Are the lights working?"
:laugh:

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