Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.Net Get Datasource name only from entity connection string?

Posted on 2015-01-12
3
Medium Priority
?
310 Views
Last Modified: 2015-01-13
Hello all,

I have the following as an example:

<add name="CustomerEntities" connectionString="metadata=res://*/Customer.csdl|res://*/Customer.ssdl|res://*/Customer.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DB111-SERVER;initial catalog=Customer;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I need to get the server name only into a string variable so "DB111-SERVER".   I tried using the SQL SqlConnectionStringBuilder but it throws an error on metadata doesn't understand it.
0
Comment
Question by:sbornstein2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 2000 total points
ID: 40545574
Yes, SqlConnectionStringBuilder doesnt understand the metadata part.

Why is your connection string formed like this, containing another connection string inside it?

You could use simple string operations to split the connection string parts using the delimiter (;) and then extracting the data source name from it.
            var connString = ConfigurationManager.ConnectionStrings["CustomerEntities"].ConnectionString;
            var parts = connString.Split(';');
            var dataSourcePart = parts.FirstOrDefault(p => p.StartsWith("data source="));

Open in new window


Because of the strange connectionString in connectionString value that you have, you will get this item in the array
"provider connection string=\"data source=DB111-SERVER"
instead of
"data source=DB111-SERVER"
0
 

Author Comment

by:sbornstein2
ID: 40546670
Entity Framework needs the metadata to build your entity mappings.
0
 

Author Closing Comment

by:sbornstein2
ID: 40546984
tx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question