tags:

views:

20

answers:

2

Tried seemingly everything here to get this to work but I keep getting "Keyword not supported" errors for just about every iteration of dsn-less connection strings I can find out there in internet land, two are shown below.

Public cnSystem As New SqlClient.SqlConnection

Public Sub ConnectToSQL()

    Dim sConnectionString As String
    Dim sServer As String

    Try
        'Always connect to production server to get startup environment variables
        If gbIsProduction Then
            If gsProductionServer = "" Then
                sServer = "xxxxx-SQL"
            Else : sServer = gsProductionServer
            End If
        Else : sServer = gsDevelopmentServer
        End If
        //Doesn't work
        sConnectionString = "Network Library=DBMSSOCN;Data Source=xxxxx-SQL,1433;Inital Catalog=xxxxx;User ID=sa;Password=xxxxx;"
        //Doesn't work
        sConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;UserId=sa;Initial Catalog=xxxxx;Data Source=xxxxx-SQL;Password=xxxxx;"  
        cnSystem.ConnectionString = sConnectionString
        cnSystem.Open()
        cmdSystem.Connection = cnSystem
    Catch ex As Exception
        RaiseError("", "modGeneral." & System.Reflection.MethodBase.GetCurrentMethod().Name, Err.Number, Err.Description)
    End Try

End Sub

Any ideas on what is the proper connection string for a DSN-less connection to a SQL server using the data objects I am using?

Thanks!

+1  A: 

try creating a udl file to create your connection string. then you can test it to ensure it is working - http://www.codeasp.net/blogs/hajan/microsoft-net/857/working-with-udl-universal-data-link-files

czuroski
I did that and the resulting connection string is the same as the second one above and I get a "Keyword not supported: 'provider'." error.
Tom
+2  A: 

While not the exact answer, this website helps me all the time:

http://www.connectionstrings.com/

Also, when using System.Data.SQLClient you do not have to specify the provider and I believe you will get the error you are receiving. Remove that part.

Mike Cheel
Awesome, that worked but now all my data sources bomb out if I try a DSN-less connection string there. The one defined in My Project > Settings > (Connection String)...any idea why?
Tom
Do you have a sample of what is there? I am in the middle of installing something that is consuming my computers soul and so I can't open VB right now. Show me what you have right now if you can (change the sensitive stuff obviously). And what version of VS are you using?
Mike Cheel
VS 2010. Basically I have data sets that are tied to a connection string and I needed to change the connection string to DSN-less. I figured that out after much teeth-gnashing and now I just need to figure out how to change a data set's connection string on the fly so I can work in both a dev and prod environment. Seems like you can change the connection string of a table adapter which is more overhead than just changing the application scope connection string which I can't figure out. Does any of that make any sense? =)
Tom
Nevermind, I figured it out, just set My.Settings("[Connection String Name") when you need to. Thanks!
Tom
I'm glad I could help. Also, if you ever decide to program in C# this article is useful: http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx
Mike Cheel
Oh and ConfigurationManager.Connectionstrings to access connection strings setup through the properties.
Mike Cheel