Q: using DSN

G

Guest

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,
 
G

Guest

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 said:
Jim,

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

Regards

Daniel Walzenbach

JIM.H. said:
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,
 
D

Daniel Walzenbach

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. said:
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 said:
Jim,

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

Regards

Daniel Walzenbach

JIM.H. said:
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,
 
G

Guest

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=myPassword"
/>
</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/d...us/off2000/html/acconAboutODBCDataSources.asp


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

For Anything & Everything, Please Let Me Know

Bye
Venkat_KL
 
J

Juan T. Llibre

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.





JIM.H. said:
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 said:
Jim,

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

Regards

Daniel Walzenbach

JIM.H. said:
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,
 
G

Guest

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,
 
G

Guest

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,
 
J

Juan T. Llibre

re:
once I create DSN how do I use it in the code?

I don't think you can use it, Jim.

There's no way for the DSN or FILEDSN parameters to be inserted
into a SQLConnection or a SQLCommand object, at least as far as I know.

That is why when you asked earlier :
Will this "SqlCommand sqlCmd = new SqlCommand(sqlStr, myDSN);" work?

I replied : "No, it won't."

And, in the other thread you started on the same subject, I said :
Other than a DSN is not an property of SqlConnection,
and therefore you cannot use DSN with a SqlConnection

I just don't think that it can be done.
If you learn a way to do that, please post it and I will change my opinion.
 
G

Guest

Hi Juan,

I see your point, I am not just understanding if DSN definition is possible
in APS.Net, where and how I will use it?

Here is a connection string I can use it ASP;
Set objADODBConn = CreateObject("ADODB.Connection")
strConn="DSN=" & MyODBC & ";UID=" & MyUsername & ";PWD=" & MyPassword & ";"
objADODBConn.Open(strConn)

I could not believe that Microsoft does not allow this kind of thing in
ASP.Net for SQL connection. DSN is still using native SQL Server driver in
the system.
However thank you very much for your time.
 
J

Juan T. Llibre

You are trying to use ADO in ASP.NET.

For a zillion reasons that is not good.

re:
I could not believe that Microsoft does not allow
this kind of thing in ASP.Net for SQL connection.

Believe it.

Why would Microsoft include as an option something
which buries performance for web applications ?

Take a few minutes to see this ADO.NET presentation :
http://www.microsoft.com/seminar/shared/asp/view.asp?url=/Seminar/en/20020918Devt1-57/manifest.xml

Also, read the links on this page :
http://msdn.microsoft.com/library/d...cpguide/html/cpconaccessingdatawithadonet.asp

Don't beat your head against the wall by trying to use ADO in ASP.NET.
You're only going to hurt yourself.
 
L

logan

in Version 1.1 you can use
using System.Data.Odbc;
I'm pretty sure that didn't exist in 1.0,
I don't know if it is still available in 2.0.
However as many have pointed out it is rather ineffcient.
I'm going to assume you probably have a reason that requires a dsn though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top