?
Solved

Using a DSN connection in a VB.net program

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

850 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