none
lien ODBC

    Question

  • Bonjour,

    J'ai un lien odbc qui pointe sur une base SQLserver 2008 express.

    le lien odbc porte le nom sur la machine cliente de "TEST5"

    Sur le code ci-dessous en aspx.vb que faut-il renseigner dans Private Shared Function GetConnectionString() As String ?
    je vous remercie de votre réponse

    Option Explicit On
    Option Strict On

    Imports System
    Imports System.Data
    Imports System.Data.Odbc

    Public Class Program
        Public Shared Sub Main()

            Dim connectionString As String = GetConnectionString()
            Dim queryString As String = _
                "SELECT CategoryID, CategoryName FROM Categories;"

            Using connection As New OdbcConnection(connectionString)
                Dim command As OdbcCommand = connection.CreateCommand()
                command.CommandText = queryString
                Try
                    connection.Open()
                    Dim dataReader As OdbcDataReader = _
                     command.ExecuteReader()
                    Do While dataReader.Read()
                        Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", _
                         dataReader(0), dataReader(1))
                    Loop
                    dataReader.Close()

                Catch ex As Exception
                    Console.WriteLine(ex.Message)
                End Try
            End Using
        End Sub

        Private Shared Function GetConnectionString() As String
            ' To avoid storing the connection string in your code, 
            ' you can retrieve it from a configuration file.
            ' Assumes Northwind.mdb is located in c:\Data folder.
            Return "Driver={Microsoft Access Driver (*.mdb)};" _
               & "Dbq=c:\Data\Northwind.mdb;Uid=Admin;Pwd=;"
        End Function
    End Class

    Wednesday, March 28, 2012 4:24 PM

Answers

  • Bonjour,

    Pour SQL Server via ODBC utilisez la chaîne de connexion suivante :

    Driver={SQL Server Native Client 10.0};Server=IPouNomDuServeur;Database=baseDeDonnées;Uid=login;Pwd=motdepasse;

    Cordialement


    Gilles TOURREAU - MVP C#
    Architecte logiciel/Consultant/Formateur Freelance
    Blog : http://gilles.tourreau.fr
    - MCPD : Enterprise Developper / Windows Developper 3.5 / ASP .NET 3.5/4.0
    - MCITP : SQL Server 2008 Developper
    - MCTS : ADO .NET 3.5 / SQL Server 2008 Developper / Windows Forms 3.5 / ASP .NET 3.5/4.0

    Wednesday, March 28, 2012 7:56 PM