I have a webservice I am creating. I am needing to connect to a SQL server on
a different machine using SQL authetication. I have the connection string
located in the machine.config. Could somebody give me a sample of how to use
that connection string to connect to the database from inside a webservice.
It's not any different than connecting from an ASP.NET page so if you know
how to do that, you should be all set. It's not a good practice to place
passwords in a config file so you should look into using Windows
authentication or at the very least encrypt the password in the config file.
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>I have a webservice I am creating. I am needing to connect to a SQL server
>on
> a different machine using SQL authetication. I have the connection string
> located in the machine.config. Could somebody give me a sample of how to
> use
> that connection string to connect to the database from inside a
> webservice.
|||This is my first attempt at pulling in the connection string from the
machine.config. Windows Authentication is not an option since the database
and webservers are on different domains and a DMZ is in use. I currently have
the SSL encryption on, but have not encrypted the actually value in the
config file (yet). That is the next step after I get the programs working
this way.
"Roman Rehak" wrote:
> It's not any different than connecting from an ASP.NET page so if you know
> how to do that, you should be all set. It's not a good practice to place
> passwords in a config file so you should look into using Windows
> authentication or at the very least encrypt the password in the config file.
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>
>
|||in web.config:
<appSettings>
<add key="ConnectionString" value="Data Source=MyServer;Initial
Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
</appSettings>
in the web service:
string cnString =
ConfigurationManager.AppSettings.Get("ConnectionSt ring");
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...[vbcol=seagreen]
> This is my first attempt at pulling in the connection string from the
> machine.config. Windows Authentication is not an option since the database
> and webservers are on different domains and a DMZ is in use. I currently
> have
> the SSL encryption on, but have not encrypted the actually value in the
> config file (yet). That is the next step after I get the programs working
> this way.
> "Roman Rehak" wrote:
|||I am not using the appSettings section of the web.config. I was planning on
using the connectionstrings section of the machine.config. There will be many
applications using the same connection string and I feel it would be
appropiate to put there, I just don't know how to get to this section.
"Roman Rehak" wrote:
> in web.config:
> <appSettings>
> <add key="ConnectionString" value="Data Source=MyServer;Initial
> Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
> </appSettings>
> in the web service:
> string cnString =
> ConfigurationManager.AppSettings.Get("ConnectionSt ring");
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...
>
>
|||The code is the same whether you want to read from machine.config or
web.config. If you have the same value in both, web.config takes precedence.
Here is how you get a connection string from the connectionStrings section:
cnString =
ConfigurationManager.ConnectionStrings["Connection StringAW"].ConnectionString;
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:F14C7CAD-93C8-4EA4-8358-9FC2B2E8E681@.microsoft.com...[vbcol=seagreen]
>I am not using the appSettings section of the web.config. I was planning on
> using the connectionstrings section of the machine.config. There will be
> many
> applications using the same connection string and I feel it would be
> appropiate to put there, I just don't know how to get to this section.
> "Roman Rehak" wrote:
Showing posts with label needing. Show all posts
Showing posts with label needing. Show all posts
Sunday, 11 March 2012
connect from webservice
Labels:
authetication,
connect,
connection,
creating,
database,
machine,
microsoft,
mysql,
needing,
ona,
oracle,
server,
sql,
webservice
connect from webservice
I have a webservice I am creating. I am needing to connect to a SQL server o
n
a different machine using SQL authetication. I have the connection string
located in the machine.config. Could somebody give me a sample of how to use
that connection string to connect to the database from inside a webservice.It's not any different than connecting from an ASP.NET page so if you know
how to do that, you should be all set. It's not a good practice to place
passwords in a config file so you should look into using Windows
authentication or at the very least encrypt the password in the config file.
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>I have a webservice I am creating. I am needing to connect to a SQL server
>on
> a different machine using SQL authetication. I have the connection string
> located in the machine.config. Could somebody give me a sample of how to
> use
> that connection string to connect to the database from inside a
> webservice.|||This is my first attempt at pulling in the connection string from the
machine.config. Windows Authentication is not an option since the database
and webservers are on different domains and a DMZ is in use. I currently hav
e
the SSL encryption on, but have not encrypted the actually value in the
config file (yet). That is the next step after I get the programs working
this way.
"Roman Rehak" wrote:
> It's not any different than connecting from an ASP.NET page so if you know
> how to do that, you should be all set. It's not a good practice to place
> passwords in a config file so you should look into using Windows
> authentication or at the very least encrypt the password in the config fil
e.
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>
>|||in web.config:
<appSettings>
<add key="ConnectionString" value="Data Source=MyServer;Initial
Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
</appSettings>
in the web service:
string cnString =
ConfigurationManager.AppSettings.Get("ConnectionString");
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...[vbcol=seagreen]
> This is my first attempt at pulling in the connection string from the
> machine.config. Windows Authentication is not an option since the database
> and webservers are on different domains and a DMZ is in use. I currently
> have
> the SSL encryption on, but have not encrypted the actually value in the
> config file (yet). That is the next step after I get the programs working
> this way.
> "Roman Rehak" wrote:
>|||I am not using the appSettings section of the web.config. I was planning on
using the connectionstrings section of the machine.config. There will be man
y
applications using the same connection string and I feel it would be
appropiate to put there, I just don't know how to get to this section.
"Roman Rehak" wrote:
> in web.config:
> <appSettings>
> <add key="ConnectionString" value="Data Source=MyServer;Initial
> Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
> </appSettings>
> in the web service:
> string cnString =
> ConfigurationManager.AppSettings.Get("ConnectionString");
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...
>
>|||The code is the same whether you want to read from machine.config or
web.config. If you have the same value in both, web.config takes precedence.
Here is how you get a connection string from the connectionStrings section:
cnString =
ConfigurationManager.ConnectionStrings["ConnectionStringAW"].ConnectionS
tring;
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:F14C7CAD-93C8-4EA4-8358-9FC2B2E8E681@.microsoft.com...[vbcol=seagreen]
>I am not using the appSettings section of the web.config. I was planning on
> using the connectionstrings section of the machine.config. There will be
> many
> applications using the same connection string and I feel it would be
> appropiate to put there, I just don't know how to get to this section.
> "Roman Rehak" wrote:
>
n
a different machine using SQL authetication. I have the connection string
located in the machine.config. Could somebody give me a sample of how to use
that connection string to connect to the database from inside a webservice.It's not any different than connecting from an ASP.NET page so if you know
how to do that, you should be all set. It's not a good practice to place
passwords in a config file so you should look into using Windows
authentication or at the very least encrypt the password in the config file.
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>I have a webservice I am creating. I am needing to connect to a SQL server
>on
> a different machine using SQL authetication. I have the connection string
> located in the machine.config. Could somebody give me a sample of how to
> use
> that connection string to connect to the database from inside a
> webservice.|||This is my first attempt at pulling in the connection string from the
machine.config. Windows Authentication is not an option since the database
and webservers are on different domains and a DMZ is in use. I currently hav
e
the SSL encryption on, but have not encrypted the actually value in the
config file (yet). That is the next step after I get the programs working
this way.
"Roman Rehak" wrote:
> It's not any different than connecting from an ASP.NET page so if you know
> how to do that, you should be all set. It's not a good practice to place
> passwords in a config file so you should look into using Windows
> authentication or at the very least encrypt the password in the config fil
e.
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:7A009E7B-EE22-4FFC-8B4B-FE870659D985@.microsoft.com...
>
>|||in web.config:
<appSettings>
<add key="ConnectionString" value="Data Source=MyServer;Initial
Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
</appSettings>
in the web service:
string cnString =
ConfigurationManager.AppSettings.Get("ConnectionString");
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...[vbcol=seagreen]
> This is my first attempt at pulling in the connection string from the
> machine.config. Windows Authentication is not an option since the database
> and webservers are on different domains and a DMZ is in use. I currently
> have
> the SSL encryption on, but have not encrypted the actually value in the
> config file (yet). That is the next step after I get the programs working
> this way.
> "Roman Rehak" wrote:
>|||I am not using the appSettings section of the web.config. I was planning on
using the connectionstrings section of the machine.config. There will be man
y
applications using the same connection string and I feel it would be
appropiate to put there, I just don't know how to get to this section.
"Roman Rehak" wrote:
> in web.config:
> <appSettings>
> <add key="ConnectionString" value="Data Source=MyServer;Initial
> Catalog=AdventureWorks;User Id=MyUser;Password=MyPassword;"/>
> </appSettings>
> in the web service:
> string cnString =
> ConfigurationManager.AppSettings.Get("ConnectionString");
> Roman
> --
> Roman Rehak
> http://sqlblog.com/blogs/roman_rehak
>
> "wendld" <GenieLifts@.news.postalias> wrote in message
> news:D1B8082F-16ED-47B7-9FD8-C5A1EBF26DED@.microsoft.com...
>
>|||The code is the same whether you want to read from machine.config or
web.config. If you have the same value in both, web.config takes precedence.
Here is how you get a connection string from the connectionStrings section:
cnString =
ConfigurationManager.ConnectionStrings["ConnectionStringAW"].ConnectionS
tring;
Roman
Roman Rehak
http://sqlblog.com/blogs/roman_rehak
"wendld" <GenieLifts@.news.postalias> wrote in message
news:F14C7CAD-93C8-4EA4-8358-9FC2B2E8E681@.microsoft.com...[vbcol=seagreen]
>I am not using the appSettings section of the web.config. I was planning on
> using the connectionstrings section of the machine.config. There will be
> many
> applications using the same connection string and I feel it would be
> appropiate to put there, I just don't know how to get to this section.
> "Roman Rehak" wrote:
>
Labels:
authetication,
connect,
connection,
creating,
database,
machine,
microsoft,
mysql,
needing,
ona,
oracle,
server,
sql,
webservice
Subscribe to:
Posts (Atom)