Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
I have full version of sql server 2005 installed on my machine i am trying to add connection string in web.config file like this

<add name="myconnectionstring";connectionString="data source=.;DataBase=mydatabase;Uid=user;Pwd=password" />


but its not working it doesn't connects.

When i tried like this

XML
<remove name="LocalSqlServer"/>
    <add name="LocalSqlServer";connectionString="data source=.;DataBase=mydatabase;Uid=user;Pwd=password"/>



it worked but i want to know why its not working with my own connection string name like above.

Thanks and regards
Posted
Updated 11-Apr-11 18:10pm
v2

The reason could be, your DataSource control which you use in the code might referring to the ConnectionString setting named "LocalSqlServer".

Check your implementation place what key you are referring to.

Point I noticed:
IMO both connection string should not work as it is not constructed properly.

XML
<add name="LocalSqlServer";


You should not put ";" next to name attribute in the add tag.
 
Share this answer
 
XML
<connectionStrings>
    <add name="OsmEmpConString" connectionString="Data Source=.\sqlexpress;Initial Catalog=AgentDB; User ID= Sqluser ; Password= Change;"
    providerName="System.Data.SqlClient" />
  </connectionStrings>


DataSource = Your database source
Initial Catalog = Database name
User ID = User id of the database
Password = Password to the database
 
Share this answer
 
XML
<connectionStrings>
    <add name="connection_string" connectionString="server=YOUR_PC_NAME_OR_SERVER_NAME; database=DATABASE_NAME; integrated security=true"/>
  </connectionString>


IT WORKS (TESTED CODE)
 
Share this answer
 
v2
Comments
ProgrammerAt 12-Apr-11 2:00am    
Hi, its not working for me it says " An error was encountered"
don't know why :(
<add name="yoConnectionString" connectionString="Data Source=Your Data Source;Initial Catalog=RecruitmentPortal;User ID= user; Password=123" providerName="System.Data.Client"/>
 
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