?
Solved

Using a DSN connection in a VB.net program

Posted on 2006-11-09
7
Medium Priority
?
406 Views
Last Modified: 2008-03-06
Good Afternoon

I use the following code to build my connection string in VB.net:

  Dim BuildConnectionString As String
  BuildConnectionString = "DSN=" + g_DSNName + ";UID=" + g_UserId + ";PWD=" + g_Password
  Dim odbcConnect As New OdbcConnection(BuildConnectionString)


Being that my DSN is set-up with sa, I am not really sure I fully understand how the connection string actually works.
Is the UID and PWD, used in the connection string, the ones in the DSN or is the UID and PWD for connecting to the database once the DSN gets
you to the server?

Thanks,
Ed

0
Comment
Question by:lbsi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Dimandja
ID: 17908032
When using a DSN, you shoyuld not specify anything else.

Example using DSN:

        Dim sConnString = "DSN=Pubs_DSN"
        Dim oODBCConnection = New Odbc.OdbcConnection(sConnString)
         Try
            oODBCConnection.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


Example DSN-less:

        Dim connectionString = "Driver={SQL Server};Server=SQLservername;Database=pubs;Uid=;Pwd=;"
        Dim oODBCConnection = New Odbc.OdbcConnection(connectionString)
        Try
            oODBCConnection.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try



Pubs_DSN is:

Data Source Name: Pubs_DSN
Server: <SQLservername>
Database: pubs
Use Integrated Security: Yes
0
 
LVL 6

Expert Comment

by:riyazthad
ID: 17908037
Ed,

Are you getting any error from your code? Are you using windows authetication, DB server credentials? If windows authentication are using , just need DSN in connection string.

If you are getting error from above code add 'Trusted_Connection=False' in your connection string.

Thad
0
 
LVL 7

Expert Comment

by:Dimandja
ID: 17908048
Go here for more examples: http://www.connectionstrings.com/
0
 
LVL 7

Accepted Solution

by:
Dimandja earned 2000 total points
ID: 18085547
I think the examples I gave fully answered this question.
0
 

Author Comment

by:lbsi
ID: 18131105
I apologize for not accepting the answer from Dimandja.  The information assisted me in finding the solution.  Please assign point total to Dimandja.  In the future, I will be more diligent in accepting answers and assigning points.

Thanks,
Ed
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question