Click here to Skip to main content
11,927,378 members (45,197 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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;

but i am unable to do that.

Here is my connection string in web.config

 <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" />
Posted 10-May-13 23:13pm
Edited 17-May-13 0:38am
Tadit Dash 11-May-13 4:28am
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
ThePhantomUpvoter 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
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

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.
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 17 May 2013
Copyright © CodeProject, 1999-2015
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