DataBase - Connecting to SQL Server
Asked By Jim Devenish
22-Nov-10 12:08 PM

I connect my Access database to a SQL Server in two different ways:
1 with ADO such as:
Dim theConnectionString
theConnectionString = Driver=SQL Server; Server=Server
\TRUTIMEV3;Database=Intelligent;User ID=xxx;Password=xxx;
Dim rec As ADODB.Recordset
Set rec = New ADODB.Recordset
Dim theSQLString
theSQLString = "Select * From [Cost Centres] Where CC_Code = '" &
theJobDigits & "'"
rec.Open theSQLString, theConnectionString, adOpenStatic,
adLockOptimistic
2 with DAO such as:
Dim theViewName
theViewName = "aView"
Dim aTable As DAO.TableDef
Set aTable = CurrentDb.CreateTableDef(theViewName)
aTable.Connect = ODBC;APP=Microsoft Data Access
Components;Trusted_Connection=Yes;Driver=SQL Server; Server=Server
\TRUTIMEV3;Database=Intelligent;User ID=xxx;Password=xxx;
aTable.SourceTableName = theViewName
CurrentDb.TableDefs.Append aTable
CurrentDb.TableDefs.Refresh
Both versions have been working satisfactorily for a number of years.
Last week the Server needed to be rebuilt and the suppliers of the SQL
database introduced a User ID and Password that had not been used
before. Other than that I am not aware of any changes to the system.
Now the first version (ADO) still works but the other (DAO) does not.
It fails when appending the table, indicating a connection failure:
Connection Failed
SQLState: 01500
SQL Server Error: 0
[Microsoft][ODBC SQL Server Driver] Invalid connection string
attribute
Connection failed:
SQLState: 08004
SQL Server Error: 4060
Server rejected the connection; Access to selected database has been
denied
Any help with getting the connection string correct would be welcome.
Microsoft Data Access Components Driver SQL Server
(1)
SQL Server
(1)
Connecting to SQL Server
(1)
Driver SQL Server
(1)
Error
(1)
ADODB
(1)
Bit
(1)
DB
(1)
Bob Barrows replied to Jim Devenish

used to establish the connection. Since the database requires a user
name and password, you should remove the Trusted_connection attribute or
set it to No. You should use the ODBC names for the user and password
attributes: UID and PWD instead of "User ID" and "Password". Also,
should not that connection string be quoted? Like this:
aTable.Connect = "ODBC;APP=Microsoft Data Access" & _
PS. I know you say it is been "working for years", but it is really not a
good idea to use implicit ADO connections. The line:
rec.Open theSQLString, theConnectionString ...
causes ADO to open a connection object behind the scenes (implicitly),
an object over which you have no control. If you are opening multiple
recordsets in your application, the result could well be that a separate
open connection to the database will exist for each recordset you have
opened, each of which consumes resources both on the client machine as
well as on the database server. Eventually, the point could be reached
where your database server refuses new connections. Best practice is to
explicitly create a connection object and use that to open your
recordsets:
dim cn as adodb.connection
set cn=new adodb.connection
cn.open "your connection string"
...
rec.Open theSQLString, cn, ...
Close the connection object when finished using it so that it goes back
into the pool of connections that can be re-used.
Also, you should get away from using ODBC with ADO as it creates an
extra software layer. Use the native OLE DB provider for SQL that is
relevant for the version of sql server you are connecting to. You can
find the relevant OLE DB connection strings here:
http://www.connectionstrings.com/
--
HTH,
Bob Barrows
Jim Devenish replied to Bob Barrows
=3D '" &
r
ings.com/
Many thanks Bob. It is now working. I do not use/create connection
strings very often and so am not sufficiently familiar with all the
syntax. I had not appreciated that I needed UID and PWD instead of
User ID and Password for an ODBC connection. That did the trick.
Prior to last week there was no password protection on the SQL
database and so I had not needed these parameters before.
Thanks for the advice on the connection object.
The missing quotes were caused by a bit of copy and paste. They were
in my code!

DataBase Roger Jennings on Access / Sharepoint http: / / www.quepublishing.com / articles / article.aspx?p = 1606238 I was very dismayed reading this article, is it makes it pretty clear that in-house hosting of your Sharepoint server with Access Services to support browser-based Access apps is something only large companies will be able to afford, because the pricing and licensing for the Enterprise version is very, very steep. The alternative is hosted Sharepoint / Access Services, and the costs do not seem terribly high. It seems to me that the pricing is upside-down. Big enterprises do not want to deploy Access apps in the browser - - they will build their own .NET apps, browser-based or not 2010 does not really save them money (because of the 64-bit requirements of Sharepoint Server 2010, it could vastly increase those costs for organizations with legacy hardware). The features of Access 2010 used in conjunction with Sharepoint 2010 seem to me to be most compelling for
DataBase Might be outgrowing Access but daunted by SQL Server I am close to completing the consolidation of various small Access databases and a couple of Excel spreadsheets that my little company uses (5 staff) into an all encompasing Access database and I was planning on splitting the database when I was finished to allow more and more obvious to me that I am going to need to give staff access to this new database from remote locations (outside of our office network). Two staff members have spent the last 10 hours downloading, installing and trying to get my head around Microsoft SQL Server 2008 Express and how it might help me out. It all started when I
DataBase SQL query slow Hi In the code below I found that it takes 1.3 seconds to load. There is a possible reason, it reads from a local MDB file (access), and it reads from some 270000 rows (result some 15-20 rows, where the highest are counted 150000, 50000, 40000, 26000, remaining are 100's). This is probably more Access that Visual Studio, though - is there a way to split it up or cancel the query? And can I read this faster? string sql = EquipmentID(Equipment) + StartDate.ToOADate().ToString(FloatFormat, myCulture) + EndDate.ToOADate().ToString(FloatFormat, myCulture sql + = " group by event_id, name"; _Log("Calc thread #2"); OleDbCommand com = new OleDbCommand(sql, con); _Log("Calc thread #3"); From #2 to #3 it takes 1.3 seconds. Remaing the query is what slows it down. Hi, Besides that your code is full of SQL injection bugs because of missing parameter bindings, you need to analyze the SQL. Create an execution plan of your statement. The free SQL server edition might help for
DataBase SQL Server Hall?schen, ich habe mit einem SQL Server noch nie was am Hut gehabt. Alles was ich bisher gemacht hatte, da war Access immer ausreichend. Nun aber ist eine Anforderung, das ein Backend auf einem SQL-Server laufen soll, wobei dar?ber noch nicht fertig diskutiert ist. Ich habe da noch eine alte Vollversion von VB6, dort ist ein SQL-Server dabei (fracht mich aber nicht welche Version, der Karton mit der VB6 steht noch