Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Q: using DSN

Reply
Thread Tools

Q: using DSN

 
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      11-10-2005
Hello,
I have the following lines to read connection string from web.config;

string cStr = ConfigurationSettings.AppSettings["connectionString"];
SqlConnection sqlConn = new SqlConnection(cStr);
this.sqlConnection1.ConnectionString = cStr;

How can replace this with a DSN (ODBC connection) I defined in my current
machine?
Thanks,

 
Reply With Quote
 
 
 
 
Daniel Walzenbach
Guest
Posts: n/a
 
      11-10-2005
Jim,

have a look at:
http://www.connectionstrings.com/

Regards

Daniel Walzenbach

"JIM.H." <> schrieb im Newsbeitrag
news:8D7D59CC-BBDB-464B-AF3C-...
> Hello,
> I have the following lines to read connection string from web.config;
>
> string cStr = ConfigurationSettings.AppSettings["connectionString"];
> SqlConnection sqlConn = new SqlConnection(cStr);
> this.sqlConnection1.ConnectionString = cStr;
>
> How can replace this with a DSN (ODBC connection) I defined in my current
> machine?
> Thanks,
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      11-10-2005
Hi Daniel,
Thanks you for your reply. I was checking that site I did not really see
how I could use a DSN called myDSN for SQL server connection in there. Can
you give me specific example?
Thanks,


"Daniel Walzenbach" wrote:

> Jim,
>
> have a look at:
> http://www.connectionstrings.com/
>
> Regards
>
> Daniel Walzenbach
>
> "JIM.H." <> schrieb im Newsbeitrag
> news:8D7D59CC-BBDB-464B-AF3C-...
> > Hello,
> > I have the following lines to read connection string from web.config;
> >
> > string cStr = ConfigurationSettings.AppSettings["connectionString"];
> > SqlConnection sqlConn = new SqlConnection(cStr);
> > this.sqlConnection1.ConnectionString = cStr;
> >
> > How can replace this with a DSN (ODBC connection) I defined in my current
> > machine?
> > Thanks,
> >

>
>
>

 
Reply With Quote
 
Daniel Walzenbach
Guest
Posts: n/a
 
      11-10-2005
Jim,

have you tried those entries?

a.. DSN:

"DSN=myDsn;Uid=username;Pwd=;"


a.. File DSN:

"FILEDSN=c:\myData.dsn;Uid=username;Pwd=;"


Daniel


"JIM.H." <> schrieb im Newsbeitrag
news:5E0C6343-CF4C-473C-BE4F-...
> Hi Daniel,
> Thanks you for your reply. I was checking that site I did not really see
> how I could use a DSN called myDSN for SQL server connection in there. Can
> you give me specific example?
> Thanks,
>
>
> "Daniel Walzenbach" wrote:
>
>> Jim,
>>
>> have a look at:
>> http://www.connectionstrings.com/
>>
>> Regards
>>
>> Daniel Walzenbach
>>
>> "JIM.H." <> schrieb im Newsbeitrag
>> news:8D7D59CC-BBDB-464B-AF3C-...
>> > Hello,
>> > I have the following lines to read connection string from web.config;
>> >
>> > string cStr = ConfigurationSettings.AppSettings["connectionString"];
>> > SqlConnection sqlConn = new SqlConnection(cStr);
>> > this.sqlConnection1.ConnectionString = cStr;
>> >
>> > How can replace this with a DSN (ODBC connection) I defined in my
>> > current
>> > machine?
>> > Thanks,
>> >

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?VmVua2F0X0tM?=
Guest
Posts: n/a
 
      11-10-2005
Hi Dear JIM.H,

This is the sample where you give all your connection string values inside
the asp.net file (ie. for example: in code behind)

But in your case You have to give

either

"DSN=mySystemDSN;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"

or

"FILEDSN=c:\somepath\mydb.dsn;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"

in you web.config in <appSettings></appSettings> section like below

<configuration>
<appSettings>
<add key="pubsDSN" value="DSN=mySystemDSN;Uid=myUsername;Pwd=myPasswo rd"
/>
</appSettings>
</configuration>

OR

<configuration>
<appSettings>
<add key="pubsFileDSN"
value="FILEDSN=c:\somepath\mydb.dsn;Uid=myUsername ;Pwd=myPassword"/>
</appSettings>
</configuration>

and

in your code behind to access the web.config file DSN/FileDSN

Dim dsn As String = ConfigurationSettings.AppSettings("pubsDSN")
or
Dim dsn As String = ConfigurationSettings.AppSettings("pubsFileDSN")


ODBC DSN
=======
Using an ODBC DSN (Data Source Name) is a two step process.

1) You must first create the DSN via the "ODBC Data Source Administrator"
program found in your computer's Control Panel (or Administrative Tools menu
in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when
using ASP(I think same thing holds good for ASP.NET).

2) Then use the following connection string - with your own DSN
name of course.

DSN
====
oConn.Open "DSN=mySystemDSN;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"

File DSN
======
oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _
"Uid=myUsername;" & _
"Pwd=myPassword"

Note:
====
The problem with DSN is that Users can (and will) modify or delete them by
mistake, then your program won't work so well. So it's better to use a
DSN-Less or OLE DB Provider connection string - with a Trusted Connection if
possible!



About ODBC data sources
================
http://msdn.microsoft.com/library/de...ataSources.asp


Login System (ASP.NET)
================
http://www.codeproject.com/Purgatory/Login_System.asp

For Anything & Everything, Please Let Me Know

Bye
Venkat_KL
 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      11-10-2005
Other than a DSN is not an property of SqlConnection,
and therefore you cannot use DSN with a SqlConnection,

(Click the "Read more" icon under "Data Shape", at http://www.connectionstrings.com/
and then click "All SqlConnection connectionstring properties", so that
the table of properties for the ADO.NET SqlConnection object opens.)

....the question I would ask is :

why would you want to use an OLEDB for ODBC provider
rather than the native SQL provider for SQL Server ?

Typically, this will result in slower performance, because you'd
have to go through an additional layer from OLEDB to ODBC.

You can use the OLEDB driver directly or, far more recommended, use the native
SQLConnection ADO.NET object, which uses native SQL Server methods to do
the job quite a bit more efficiently than either OLEDB or ODBC.




Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"JIM.H." <> wrote in message
news:5E0C6343-CF4C-473C-BE4F-...
> Hi Daniel,
> Thanks you for your reply. I was checking that site I did not really see
> how I could use a DSN called myDSN for SQL server connection in there. Can
> you give me specific example?
> Thanks,
>
>
> "Daniel Walzenbach" wrote:
>
>> Jim,
>>
>> have a look at:
>> http://www.connectionstrings.com/
>>
>> Regards
>>
>> Daniel Walzenbach
>>
>> "JIM.H." <> schrieb im Newsbeitrag
>> news:8D7D59CC-BBDB-464B-AF3C-...
>> > Hello,
>> > I have the following lines to read connection string from web.config;
>> >
>> > string cStr = ConfigurationSettings.AppSettings["connectionString"];
>> > SqlConnection sqlConn = new SqlConnection(cStr);
>> > this.sqlConnection1.ConnectionString = cStr;
>> >
>> > How can replace this with a DSN (ODBC connection) I defined in my current
>> > machine?
>> > Thanks,



 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      11-10-2005
Hi Venkat_KL,
Thank you very much for all this great help. Since I am using
“this.sqlConnection1.ConnectionString†in many places such as “SqlCommand
sqlCmd = new SqlCommand(sqlStr, connStr);†When I read my DSN from web.config
with the example you gave, how should I use it instead of
“this.sqlConnection1.ConnectionString†in my code? Will this “SqlCommand
sqlCmd = new SqlCommand(sqlStr, myDSN);†work? I am new in asp.net and do not
know all these details.
Thanks,




"Venkat_KL" wrote:

> Hi Dear JIM.H,
>
> This is the sample where you give all your connection string values inside
> the asp.net file (ie. for example: in code behind)
>
> But in your case You have to give
>
> either
>
> "DSN=mySystemDSN;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> or
>
> "FILEDSN=c:\somepath\mydb.dsn;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> in you web.config in <appSettings></appSettings> section like below
>
> <configuration>
> <appSettings>
> <add key="pubsDSN" value="DSN=mySystemDSN;Uid=myUsername;Pwd=myPasswo rd"
> />
> </appSettings>
> </configuration>
>
> OR
>
> <configuration>
> <appSettings>
> <add key="pubsFileDSN"
> value="FILEDSN=c:\somepath\mydb.dsn;Uid=myUsername ;Pwd=myPassword"/>
> </appSettings>
> </configuration>
>
> and
>
> in your code behind to access the web.config file DSN/FileDSN
>
> Dim dsn As String = ConfigurationSettings.AppSettings("pubsDSN")
> or
> Dim dsn As String = ConfigurationSettings.AppSettings("pubsFileDSN")
>
>
> ODBC DSN
> =======
> Using an ODBC DSN (Data Source Name) is a two step process.
>
> 1) You must first create the DSN via the "ODBC Data Source Administrator"
> program found in your computer's Control Panel (or Administrative Tools menu
> in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when
> using ASP(I think same thing holds good for ASP.NET).
>
> 2) Then use the following connection string - with your own DSN
> name of course.
>
> DSN
> ====
> oConn.Open "DSN=mySystemDSN;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> File DSN
> ======
> oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> Note:
> ====
> The problem with DSN is that Users can (and will) modify or delete them by
> mistake, then your program won't work so well. So it's better to use a
> DSN-Less or OLE DB Provider connection string - with a Trusted Connection if
> possible!
>
>
>
> About ODBC data sources
> ================
> http://msdn.microsoft.com/library/de...ataSources.asp
>
>
> Login System (ASP.NET)
> ================
> http://www.codeproject.com/Purgatory/Login_System.asp
>
> For Anything & Everything, Please Let Me Know
>
> Bye
> Venkat_KL

 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      11-10-2005
The only problem with that is that he didn't want to use <appSettings>.






Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Venkat_KL" <> wrote in message
news9318111-2B89-4CBF-AB60-...
> Hi Dear JIM.H,
>
> This is the sample where you give all your connection string values inside
> the asp.net file (ie. for example: in code behind)
>
> But in your case You have to give
>
> either
>
> "DSN=mySystemDSN;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> or
>
> "FILEDSN=c:\somepath\mydb.dsn;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> in you web.config in <appSettings></appSettings> section like below
>
> <configuration>
> <appSettings>
> <add key="pubsDSN" value="DSN=mySystemDSN;Uid=myUsername;Pwd=myPasswo rd"
> />
> </appSettings>
> </configuration>
>
> OR
>
> <configuration>
> <appSettings>
> <add key="pubsFileDSN"
> value="FILEDSN=c:\somepath\mydb.dsn;Uid=myUsername ;Pwd=myPassword"/>
> </appSettings>
> </configuration>
>
> and
>
> in your code behind to access the web.config file DSN/FileDSN
>
> Dim dsn As String = ConfigurationSettings.AppSettings("pubsDSN")
> or
> Dim dsn As String = ConfigurationSettings.AppSettings("pubsFileDSN")
>
>
> ODBC DSN
> =======
> Using an ODBC DSN (Data Source Name) is a two step process.
>
> 1) You must first create the DSN via the "ODBC Data Source Administrator"
> program found in your computer's Control Panel (or Administrative Tools menu
> in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when
> using ASP(I think same thing holds good for ASP.NET).
>
> 2) Then use the following connection string - with your own DSN
> name of course.
>
> DSN
> ====
> oConn.Open "DSN=mySystemDSN;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> File DSN
> ======
> oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _
> "Uid=myUsername;" & _
> "Pwd=myPassword"
>
> Note:
> ====
> The problem with DSN is that Users can (and will) modify or delete them by
> mistake, then your program won't work so well. So it's better to use a
> DSN-Less or OLE DB Provider connection string - with a Trusted Connection if
> possible!
>
>
>
> About ODBC data sources
> ================
> http://msdn.microsoft.com/library/de...ataSources.asp
>
>
> Login System (ASP.NET)
> ================
> http://www.codeproject.com/Purgatory/Login_System.asp
>
> For Anything & Everything, Please Let Me Know
>
> Bye
> Venkat_KL



 
Reply With Quote
 
Juan T. Llibre
Guest
Posts: n/a
 
      11-10-2005
re:
>Will this "SqlCommand sqlCmd = new SqlCommand(sqlStr, myDSN);" work?


No, it won't. See my earlier reply.



Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"JIM.H." <> wrote in message
news:280A29C6-377D-4285-A563-...
> Hi Venkat_KL,
> Thank you very much for all this great help. Since I am using
> "this.sqlConnection1.ConnectionString" in many places such as "SqlCommand
> sqlCmd = new SqlCommand(sqlStr, connStr);" When I read my DSN from web.config
> with the example you gave, how should I use it instead of
> "this.sqlConnection1.ConnectionString" in my code? Will this "SqlCommand
> sqlCmd = new SqlCommand(sqlStr, myDSN);" work? I am new in asp.net and do not
> know all these details.
> Thanks,
>
>
>
>
> "Venkat_KL" wrote:
>
>> Hi Dear JIM.H,
>>
>> This is the sample where you give all your connection string values inside
>> the asp.net file (ie. for example: in code behind)
>>
>> But in your case You have to give
>>
>> either
>>
>> "DSN=mySystemDSN;" & _
>> "Uid=myUsername;" & _
>> "Pwd=myPassword"
>>
>> or
>>
>> "FILEDSN=c:\somepath\mydb.dsn;" & _
>> "Uid=myUsername;" & _
>> "Pwd=myPassword"
>>
>> in you web.config in <appSettings></appSettings> section like below
>>
>> <configuration>
>> <appSettings>
>> <add key="pubsDSN" value="DSN=mySystemDSN;Uid=myUsername;Pwd=myPasswo rd"
>> />
>> </appSettings>
>> </configuration>
>>
>> OR
>>
>> <configuration>
>> <appSettings>
>> <add key="pubsFileDSN"
>> value="FILEDSN=c:\somepath\mydb.dsn;Uid=myUsername ;Pwd=myPassword"/>
>> </appSettings>
>> </configuration>
>>
>> and
>>
>> in your code behind to access the web.config file DSN/FileDSN
>>
>> Dim dsn As String = ConfigurationSettings.AppSettings("pubsDSN")
>> or
>> Dim dsn As String = ConfigurationSettings.AppSettings("pubsFileDSN")
>>
>>
>> ODBC DSN
>> =======
>> Using an ODBC DSN (Data Source Name) is a two step process.
>>
>> 1) You must first create the DSN via the "ODBC Data Source Administrator"
>> program found in your computer's Control Panel (or Administrative Tools menu
>> in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when
>> using ASP(I think same thing holds good for ASP.NET).
>>
>> 2) Then use the following connection string - with your own DSN
>> name of course.
>>
>> DSN
>> ====
>> oConn.Open "DSN=mySystemDSN;" & _
>> "Uid=myUsername;" & _
>> "Pwd=myPassword"
>>
>> File DSN
>> ======
>> oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _
>> "Uid=myUsername;" & _
>> "Pwd=myPassword"
>>
>> Note:
>> ====
>> The problem with DSN is that Users can (and will) modify or delete them by
>> mistake, then your program won't work so well. So it's better to use a
>> DSN-Less or OLE DB Provider connection string - with a Trusted Connection if
>> possible!
>>
>>
>>
>> About ODBC data sources
>> ================
>> http://msdn.microsoft.com/library/de...ataSources.asp
>>
>>
>> Login System (ASP.NET)
>> ================
>> http://www.codeproject.com/Purgatory/Login_System.asp
>>
>> For Anything & Everything, Please Let Me Know
>>
>> Bye
>> Venkat_KL



 
Reply With Quote
 
=?Utf-8?B?SklNLkgu?=
Guest
Posts: n/a
 
      11-10-2005
Hi Juan,
Thanks for the reply. Ok. I understand it might be little bit slow through
DSN, once I create DSN how do I use it in the code? Is there any way I can
create SQLCommand through DSN.
Thanks,

"Juan T. Llibre" wrote:

> re:
> >Will this "SqlCommand sqlCmd = new SqlCommand(sqlStr, myDSN);" work?

>
> No, it won't. See my earlier reply.
>
>
>
> Juan T. Llibre, ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Español : http://asp.net.do/foros/
> ======================================
> "JIM.H." <> wrote in message
> news:280A29C6-377D-4285-A563-...
> > Hi Venkat_KL,
> > Thank you very much for all this great help. Since I am using
> > "this.sqlConnection1.ConnectionString" in many places such as "SqlCommand
> > sqlCmd = new SqlCommand(sqlStr, connStr);" When I read my DSN from web.config
> > with the example you gave, how should I use it instead of
> > "this.sqlConnection1.ConnectionString" in my code? Will this "SqlCommand
> > sqlCmd = new SqlCommand(sqlStr, myDSN);" work? I am new in asp.net and do not
> > know all these details.
> > Thanks,
> >
> >
> >
> >
> > "Venkat_KL" wrote:
> >
> >> Hi Dear JIM.H,
> >>
> >> This is the sample where you give all your connection string values inside
> >> the asp.net file (ie. for example: in code behind)
> >>
> >> But in your case You have to give
> >>
> >> either
> >>
> >> "DSN=mySystemDSN;" & _
> >> "Uid=myUsername;" & _
> >> "Pwd=myPassword"
> >>
> >> or
> >>
> >> "FILEDSN=c:\somepath\mydb.dsn;" & _
> >> "Uid=myUsername;" & _
> >> "Pwd=myPassword"
> >>
> >> in you web.config in <appSettings></appSettings> section like below
> >>
> >> <configuration>
> >> <appSettings>
> >> <add key="pubsDSN" value="DSN=mySystemDSN;Uid=myUsername;Pwd=myPasswo rd"
> >> />
> >> </appSettings>
> >> </configuration>
> >>
> >> OR
> >>
> >> <configuration>
> >> <appSettings>
> >> <add key="pubsFileDSN"
> >> value="FILEDSN=c:\somepath\mydb.dsn;Uid=myUsername ;Pwd=myPassword"/>
> >> </appSettings>
> >> </configuration>
> >>
> >> and
> >>
> >> in your code behind to access the web.config file DSN/FileDSN
> >>
> >> Dim dsn As String = ConfigurationSettings.AppSettings("pubsDSN")
> >> or
> >> Dim dsn As String = ConfigurationSettings.AppSettings("pubsFileDSN")
> >>
> >>
> >> ODBC DSN
> >> =======
> >> Using an ODBC DSN (Data Source Name) is a two step process.
> >>
> >> 1) You must first create the DSN via the "ODBC Data Source Administrator"
> >> program found in your computer's Control Panel (or Administrative Tools menu
> >> in Windows 2000). Make sure to create a SYSTEM DSN (not a USER DSN) when
> >> using ASP(I think same thing holds good for ASP.NET).
> >>
> >> 2) Then use the following connection string - with your own DSN
> >> name of course.
> >>
> >> DSN
> >> ====
> >> oConn.Open "DSN=mySystemDSN;" & _
> >> "Uid=myUsername;" & _
> >> "Pwd=myPassword"
> >>
> >> File DSN
> >> ======
> >> oConn.Open "FILEDSN=c:\somepath\mydb.dsn;" & _
> >> "Uid=myUsername;" & _
> >> "Pwd=myPassword"
> >>
> >> Note:
> >> ====
> >> The problem with DSN is that Users can (and will) modify or delete them by
> >> mistake, then your program won't work so well. So it's better to use a
> >> DSN-Less or OLE DB Provider connection string - with a Trusted Connection if
> >> possible!
> >>
> >>
> >>
> >> About ODBC data sources
> >> ================
> >> http://msdn.microsoft.com/library/de...ataSources.asp
> >>
> >>
> >> Login System (ASP.NET)
> >> ================
> >> http://www.codeproject.com/Purgatory/Login_System.asp
> >>
> >> For Anything & Everything, Please Let Me Know
> >>
> >> Bye
> >> Venkat_KL

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
System DSN Faster Than File DSN! Arpan ASP General 7 07-02-2005 04:01 PM
How to create DSN using asp.net ? Shibu ASP .Net 6 10-06-2004 04:11 PM
Connect to Sql Server using DSN? =?Utf-8?B?QmVu?= ASP .Net 2 09-09-2004 01:09 PM
Database Connectivity using DSN Niks ASP .Net 3 01-12-2004 02:12 PM
Database Connectivity using DSN Arun K ASP .Net 1 12-23-2003 08:00 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57