Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0 MVC3
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
 
<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 10-May-13 23:13pm
Edited 17-May-13 0:38am
v3
Comments
Tadit Dash at 11-May-13 4:28am
   
What code you have tried ?
OriginalGriff at 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ő at 11-May-13 5:30am
   
You want to split it in what for exactly? And why? You want to extract something from it?
ridoy at 11-May-13 13:26pm
   
question isn't clear
ThePhantomUpvoter at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 436
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 170
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 17 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100