Avatar of Richard
Flag for United States of America

asked on 

How do I connect to SQL from VB.Net

In VB6 I was able to use:
Set dbData = New ADODB.Connection
sProvider = "SQLOLEDB.1"
dbData.ConnectionString = "Provider=" & sProvider & ";Integrated Security=SSPI;" _
                   & "Initial Catalog=" & sCatalog & ";Data Source=" & sServer

Open in new window

and everyone was happy.  The connection worked and I was able to access all my data.
Now I'm trying to move into the 21st century and use .NET with classes etc.
I have tried many variations on the following:
        dbData = New SqlConnection
        dbData.ConnectionString = "Data Source= " & sServer & "; Initial Catalog = " & sCatalog & ";  Trusted_Connection=True)"

Open in new window

I have tried to set "Integrated Security = True" or "Yes" and I get an error: Invalid value for key 'integrated security'.
If I leave off the Trusted_Connection, I get an error:{"Login failed for user ''."}
The only one that works is to use Uid and Pwd set to my windows logon user name and password.  However I need to have this work without usernames or passwords.
Anybody have any ideas about this?
By the way, the VB6 program runs fine from the same computer on which I'm doing my development - so I know that the SQL server is accessible.   SQL is setup for Windows Logon.
Visual Basic.NET.NET ProgrammingMicrosoft SQL Server

Avatar of undefined
Last Comment

8/22/2022 - Mon