TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Salman Mushtaq
NA
284
221.2k
How to get @@SERVERNAME and use in app.config file C#
Oct 25 2018 9:18 AM
Hi All,
In my winform application I use Linq to Sql.
My app.config file is following code
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name=
"SmartexFxDashboard.Properties.Settings.smartex_fx_reportsConnectionString"
connectionString=
"Data Source=(local)\SQLEXPRESS;Initial Catalog=smartex_fx_reports;Integrated Security=True"
providerName=
"System.Data.SqlClient"
/>
</connectionStrings>
<startup>
<supportedRuntime version=
"v4.0"
sku=
".NETFramework,Version=v4.6.1"
/>
</startup>
</configuration>
In Data Source I need to add 2 things
1. Server name
2. Instance name
Now if I have default instance I need to write
(local)
And in case I have names instance e.g. SQLEXPRESS I need to write
(local)/SQLEXPRESS
But I didn't know in client computer he have which instance. So, I need to know the instance name and save in key and instead of SQLEXPRESS I use that key.
In MS SQL SERVER 2008 if I execute query
select @@SERVERNAME
select @@SERVICENAME
First one gives me my laptop name / instance name and second one give me only instance name
So, I need your expertise how I get this instance name in app.config file and save in key and use it. So it's not hard coded and work for all.
Advance thanks and looking forward to your answers.
Reply
Answers (
6
)
treeview in c# web application
Naming Conventions