Solved

Using a DSN connection in a VB.net program

Posted on 2006-11-09
7
395 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
  • 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 500 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now