Re: Connecting to sql server

From: Cowboy \(Gregory A. Beamer\) [MVP] (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 07/09/04


Date: Fri, 9 Jul 2004 13:37:36 -0500

For the record: I hate Visual Basic .NET Standard.

Having said that, you should be able to do what you desire by moving away
from the "automagic" tools (wizards). Here is some code that might help:

Private Function GetData() As DataSet

    'Change the server name, database and user info
    'for your DB
    Dim connStr As String = "Server=(local);Database=" & _
                                               "pubs;UID=sa;PWD=;"
    Dim sql As String = "SELECT * FROM Authors"

    Dim conn As New SqlConnection(connStr)
    Dim cmd As New SqlCommand(sql, conn)

    'Name here should be a friendly name
    'for your dataset
    Dim ds As New DataSet("nameHere")
    Dim da As New SqlDataAdapter(cmd)

    'Change FriendlyName to a table name for your
    'data.
    da.TableMappings.Add("Table", "FriendlyName")

    Try
        conn.Open()
        da.Fill(ds)
    Finally
        If conn.ConnectionState = _
                ConnectionState.Open Then
            conn.Close()
        End If

        conn.Dispose()
    End Try

End Function

You can test this by binding a DataView to this routine:

DataView1.DataSource = GetData()
DataView1.DataBind()

-- 
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
************************************************
Think Outside the Box!
************************************************
"don" <don.ns@ns.mweco.com> wrote in message
news:UbudnTLHVuMyR3PdRVn-iQ@sigecom.net...
> If this is not correct group, please point me in right direction.
>
> I am very new to vb.net.  I purchased the standard version of Visual
> Basic.net.
>
> I am trying to get a row of data from a SQL Server on our network.
>
> I have gone to tools >  connect to databases  and set up a connection to
> our sql server.  When I test the connection, it says "Test conection
> succeeded".
>
> When I click ok in the Data Link Properties Window which just validated
the
> connection, I am asked for password to the server and I respond, then I
get
> an error message as follows:
>
> Unable to connect to database.
> It is only possible to connect to SQL Server Desktop Engine databases and
> microsoft access databases with this version of Visual Studio.
>
> Do I need to purchase something else in order to do this.  This small
> project is the reasonn I purchased the Visual Basic.Net software in the
> first place.  It said I could connect to a wide range of data sources.
>
> Thanks in advance for any help.


Relevant Pages

  • Re: Install Northwind SQL Database?
    ... connection going between Visual Studio and Espress. ... Error connecting to SQL Server 2005 under default settings SQL Server does ... tool for creating and using databases. ... install by default with SQL Express. ...
    (microsoft.public.sqlserver.setup)
  • Re: Joining tables from two databases
    ... Hitchhiker's Guide to Visual Studio and SQL Server ... account with rights to both tables. ... to create a connection I need to use a connection ... Are these 2 databases are SQL Server? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Install Northwind SQL Database?
    ... and I am now in business with SQL Server and the Northwind ... tool for creating and using databases. ... you need to create a data connection to SQL Express. ... install by default with SQL Express. ...
    (microsoft.public.sqlserver.setup)
  • Re: Connection getMetaData() does not throw SQL Exception
    ... purpose of pooling for Sql Server, it does make sense for other Databases ... sounds like you are trying to build your own pooling connection pre-testing. ...
    (microsoft.public.sqlserver.jdbcdriver)
  • Re: why>?
    ... On your desktop-- you'll be running SQL Server behind the scenes. ... it isn't risky to allow end users to create databases. ... it is no more risky than giving you the ability to create spreadsheets. ... I'm not saying that Oracle and IBM are going away. ...
    (microsoft.public.excel)

Loading