Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am doing a project on ASP.Net MVC3 using C#,Entity data model(.edmx),i Want to split connection string like
Data Source=xxx-PC;
Initial Catalog=xxx;
User ID=sa;
Password=xxxx;


but i am unable to do that.

Here is my connection string in web.config

XML
<connectionStrings>
 <add name="VidyaDaanEntities" connectionString="metadata=res://*/VidyaDaanEntities.csdl|res://*/VidyaDaanEntities.ssdl|res://*/VidyaDaanEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=xxx-PC;Initial Catalog=xxx;User ID=sa;Password=xxxx;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
Posted
Updated 16-May-13 23:38pm
v3
Comments
What code you have tried ?
OriginalGriff 11-May-13 4:30am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps if you explain what you want to split the string into it would help - an example, maybe?
Use the "Improve question" widget to edit your question and provide better information.
Zoltán Zörgő 11-May-13 5:30am    
You want to split it in what for exactly? And why? You want to extract something from it?
ridoy 11-May-13 13:26pm    
question isn't clear
[no name] 17-May-13 6:15am    
What does "i am unable to do that" mean? I do not see anywhere where you have tried to use the Split function at all.

Hi harshal

You can get the connection string follow of this sub code:

string strConnectionString=ConfigurationManager.AppSettings["ConnectionString"];

ConnectionString is the name of your connection string form web.config after that you can split the strConnectionString with
strConnectionString.Split()
method.

If you want to the get more information about connection string please review this link:
How to get Connection String from App.Config in c#[^]

Good luck

Best regards.
 
Share this answer
 
v2
Use Namespace using System.Configuration to access connectionstring

string myconnection=ConfigurationManager.AppSettings["ConnectionString"]

after that use split() to split the connectionstring

myconnection.Split(';') use index to get Data Source, Initial Catalog etc.

and again split with '='to get final value.
 
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