简体   繁体   中英

VB.NET connect to Win2008 SQL server DB

I am running Visual Studio 2008 on my Windows XP Professional SP3 box.

The server is on Windows 2008 R2 Enterprise SP1

The server is on our network, and I am able to ping it via the DNS name used in my connection string, as well as by IP address.

During the ObjDa.Fill(dsReturn) statement, this error occurs.

No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21).

    Dim strQuery As String = "select * from sys.Tables" 
    Dim strConn As String = "Server=dev.xxxxxxx.vmc;" & _
              "Uid=xxxx;PWD=xxxxx;Database=report1;Integrated Security=False;"

    Dim ObjDa As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strQuery, strConn)

    Try
        Dim dsReturn As DataSet = New DataSet
        ObjDa.Fill(dsReturn)
        ObjDa.Dispose()
        Return dsReturn
    Catch ex As Exception
        Dim strError as string = ex.Message()
    End Try

EDIT


I have changed my code to use the following line, per Tim's comment suggestion

Dim ObjDa As SqlDataAdapter = New SqlDataAdapter(pStrQuery, strConnection)

Now, I am getting This message

Login failed for user 'vmc\\adam'.

When I connect through Remote Desktop Connection to that server, log in with my windows credentials, and bring up the SQL Management Studio... the Authentication type is 'Windows Authentication' for 'VMC\\adam', and I don't type in a password.

But, when I use those same credentials in my connection string, it errors out. Ideas?


EDIT


I found a site that suggested using the following settings in the connection string, and removing the username and password, to enable windows authentication.

This is now working.

integrated security=SSPI;persist security info=False; Trusted_Connection=Yes;

When you specify a uid/password combo and set integrated security to false, it attempts to look for a sql server login as opposed to a windows login. You will want to change your connection string to this if you want to use Windows Authentication.

Server=dev.xxxxxxx.vmc;Database=report1;Integrated Security=True;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM