Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Better way of connecting to SQL 2005

Better way of connecting to SQL 2005

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestionc++sql-server
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svanwass
    wrote on last edited by
    #1

    So I am using ODBC to connect to my SQL server like such: connection = "Provider=MSDASQL;" + "Driver={SQL Native Client};" + "Server=MYSERVER;" + "Database=MYDB;" + "UID=MYUSERNAME;" + "PWD=MYPASSWORD;" + Trusted_Connection=yes;" Try Using connection As New OdbcConnection(ConnectionString) Dim command As New OdbcCommand(queryString, connection) connection.Open() Dim reader As OdbcDataReader = command.ExecuteReader() While reader.Read() station_count = reader(0).ToString End While connection.Close() reader.Close() End Using Catch ex As Exception SQLERROR = True WriteErrorLog(ex.ToString) Exit Sub End Try This is causing me a problem within my application. I wrote it using a Domain Admin which has access to the server through my SQL user, but the application needs to be deployed on a machine with much lower permission. My question is: 1. Should I rewrite the database connection using a different method instead of ODBC 2. Is there something I can do on the server to fix this? Thanks! Steve

    D 1 Reply Last reply
    0
    • S svanwass

      So I am using ODBC to connect to my SQL server like such: connection = "Provider=MSDASQL;" + "Driver={SQL Native Client};" + "Server=MYSERVER;" + "Database=MYDB;" + "UID=MYUSERNAME;" + "PWD=MYPASSWORD;" + Trusted_Connection=yes;" Try Using connection As New OdbcConnection(ConnectionString) Dim command As New OdbcCommand(queryString, connection) connection.Open() Dim reader As OdbcDataReader = command.ExecuteReader() While reader.Read() station_count = reader(0).ToString End While connection.Close() reader.Close() End Using Catch ex As Exception SQLERROR = True WriteErrorLog(ex.ToString) Exit Sub End Try This is causing me a problem within my application. I wrote it using a Domain Admin which has access to the server through my SQL user, but the application needs to be deployed on a machine with much lower permission. My question is: 1. Should I rewrite the database connection using a different method instead of ODBC 2. Is there something I can do on the server to fix this? Thanks! Steve

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Why are you using the Odbc library instead of the SqlServer (SqlConnection, SqlCommand, Sqlxxxx...) specific library? Also, if you're using TrustedConnection, it means you're using the Windows account to login to SQL Server. Specifying a username and password with SSPI (Trusted Connection = True) is pointless since it won't be used. You either specify a username and password to use (SSPI off) SQL Servers authentication, or you don't specify them and turn SSPI on to use Windows Integrated security. You can get the various connection strings for all kinds of databases and connection options from ConnectionStrings.com[^]. There is also a small reference guide on the SQL Server connection strings here[^].

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups