[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using a DSN connection in a VB.net program

Posted on 2006-11-09
7
Medium Priority
?
407 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

656 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