473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DSN ConnectionString?

I created a System DSN named "NETData" for a SQL Server 2005 Express
database. Now to make use of this System DSN to access records in the
DB table, this is how I framed the ConnectionString:

Dim sqlConn As SqlConnection

sqlConn = New SqlConnection("DSN=NETData")

But the following error gets generated pointing to the above line:

Keyword not supported: 'dsn'.

How do I overcome the above error?

Thanks,

Arpan

Aug 19 '06 #1
5 10035
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
>I created a System DSN named "NETData" for a SQL Server 2005 Express
database.
Is there a specific reason that you need to use ODBC rather than the native
..NET provider?
http://www.connectionstrings.com/
Aug 19 '06 #2
Is there a specific reason that you need to use ODBC rather than the native
.NET provider?
Actually 2 reasons....the first one being just for testing purpose &
the second one being whether DSN parameters cannot be inserted into a
SQLConnection or a SQLCommand object which I was told by one of my
colleagues though he wasn't very much sure if that's indeed the case.
So just want to get this verified from some MVPs/ASP.NET gurus.

Thanks,

Regards,

Arpan
Mark Rae wrote:
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@m79g2000cwm.googlegr oups.com...
I created a System DSN named "NETData" for a SQL Server 2005 Express
database.

Is there a specific reason that you need to use ODBC rather than the native
.NET provider?
http://www.connectionstrings.com/
Aug 19 '06 #3
Hi Arpan

I had a very similar issue connecting via ODBC to a MySQL DB, How I got
round it was to put the connection in the web.config file and used the DSN
from there.

<connectionStrings>

<add name="connectionname" connectionString="Dsn=DSNNetData"
providerName="System.Data.Odbc" />

</connectionStrings>

This worked for me in an intranet environment, I believe if you are using
this method on the Internet it is advisable to encrypt the connection. There
is a good artical on 4guysfromrolla.com on how to encrypt the connection.

HTH

rgds
bren

Why do I climb mountains? Simple! because they are there
www.3peakschallenge.co.uk


Aug 19 '06 #4
Thanks, Bren, for your input. After adding the <connectionStringstag
in the web.config file, how do I use the SqlConnection in the ASPX
page? Using the native .NET Provider, the ConnectionString I used is
shown below:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
Dim dSet As DataSet

sqlConn = New SqlConnection("Data
Source=MyDS\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True")
sqlDapter = New SqlDataAdapter("SELECT * FROM Tests", sqlConn)

dSet = New DataSet()
sqlDapter.Fill(dSet, "Tests")
......................
......................
End Sub
</script>

But now since I am setting the DSN connection in the web.config file,
how do I reference the DSN connection in the ASPX page?

This is how my web.config looks:

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<appSettings>
<connectionStrings>
<add name="NetDSN" connectionString="Dsn=NETData"
providerName="System.Data.Odbc"/>
</connectionStrings>
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true"/>
</system.web>
</configuration>

Thanks once again,

Regards,

Arpan

Bren wrote:
Hi Arpan

I had a very similar issue connecting via ODBC to a MySQL DB, How I got
round it was to put the connection in the web.config file and used the DSN
from there.

<connectionStrings>

<add name="connectionname" connectionString="Dsn=DSNNetData"
providerName="System.Data.Odbc" />

</connectionStrings>

This worked for me in an intranet environment, I believe if you are using
this method on the Internet it is advisable to encrypt the connection. There
is a good artical on 4guysfromrolla.com on how to encrypt the connection.

HTH

rgds
bren

Why do I climb mountains? Simple! because they are there
www.3peakschallenge.co.uk
Aug 20 '06 #5
Hi Arpan

Sorry for the delay in getting back to you, I've just spent the weekend in
the dentists chair having my tooth ripped out :-]

Anyhow I am assuming you are using VS 2005 here.

How I do it is as follows:

Add the connection string info into web.config - which you have now done.

Drag and drop a SqlDataSource onto your webform and
Set the following properties in the properties window:

ID - name it something like dsMyDataSource

ConnectionString - Choose your connection name from the dropdown, in this
case it should be NetDSN. This will then enter your dsn name automatically.

DataSource Mode - From the dropdown choose either DataSet or DataReader

Once you have done this you have 2 options:

1. Declare a variable in your code page to store your SQL statement in e.g.

Dim varSQL As String = "SELECT * FROM Tests"
and then add this to your dsMyDataSource at run time e.g.

Sub Page_Load(etc....

dsMyDataSource.SelectCommand = varSQL

End Sub

2. Add the SELECT Statement atribute into the HTML view of your
dsMyDataSource e.g.

SelectCommand="SELECT * FROM Tests"

I personally prefer to use option one as that gives full code separation at
runtime and you can then just reset the varSQL value for your UPDATE
command, DELETE command etc.

Hope this helps, any more questions just post on the group and I will try to
help.

Best Regards
Bren

Why do I climb mountains? Simple! because they are there
www.3peakschallenge.co.uk
Aug 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Devante | last post by:
Hi, I am fairly new to ASP.NET and have been working on a web form that will allow a user to upload images to a database. I have found a sample web form that I have been trying to get working,...
2
by: oswald verlinden | last post by:
Hi all, i have a client with an old working app. in PowerBuilder for which i need to create new modules. The db is sqlanywhere 5.0.4 The db is configured in ODBC. Now, i don't seem to be able...
2
by: G. Dean Blake | last post by:
We currently distribute a web application to serveral servers for a customer. We have been putting the connection string in our web.config file under <appSettings> <add...
6
by: Tony | last post by:
Dear All, When I run an example program on the http://www.dotnetjunkies.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/data/datagrid1.src&file=VB\datagrid1.aspx&font=3 ...
4
by: Shapper | last post by:
Hello, I have this connectionString in a DataReader: Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\db.mdb" It's working fine. Now i...
10
by: Laura K | last post by:
Tried all kinds of things. I get the error. The ConnectionString property has not been initialized. Any help appreciated. ...
2
by: Chen | last post by:
I have a project which contain several WinForms. I put a SqlDataAdapter in Many of the Forms. I want these SqlConnection1.ConnectionString Point to the same SQL Server. So I create a Global Const...
3
by: Jim Andersen | last post by:
Hi, I would appreciate if someone could explain this behaviour, and maybe offer a better solution. I have been working with the GridView control. And SqlDataSource. It works great if I do:...
3
by: Arpan | last post by:
I recently installed SQL Server 2005 (Management Studio Express) along with SQL Server 2005 Express (Configuration Manager) in my Win2K Pro m/c & use IIS 5.0 to run ASPX projects. I could add my...
5
by: Radu | last post by:
Hi. In a repeater I have as ItemTemplate the following, among others, and everything works great: <asp:SqlDataSource ID="LocationSqlDataSource" SelectCommand="SELECT blah-blah-blah"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.