Re: 2nd db connection from 12/21



Never used DAO to connect to a Sql Back end but if you can use ADO this
ought to get you going, if the server accepts remote connections on the
standard Port (I think it is Port 1433).

Dim strCon As String, strSql As String
Dim cn As ADODB.Connection, rs As ADODB.Recordset

Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
strSql = "SELECT columns FROM table " _
& "WHERE whatever ORDER BY columns"
strCon = "ODBC;" _
& "DRIVER=SQL Server;" _
& "SERVER=ServerName -OR- IP Address;" _
& "UID=UserName;" _
& "PWD=Password;" _
& "DATABASE=DatabaseName"
cn.ConnectionString = strCon
cn.Open
rs.Open strSql, cn, adOpenKeyset, adLockOptimistic
Do While Not rs.EOF
' Your Code Here
rs.MoveNext
Loop
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

The only semi difficult thing here is to get the Connection String right for
your server. There is a great resource for Connection strings here
http://www.connectionstrings.com/

Depending you your connection to the remote server this could be a pretty
slow operation, and again depending on your connection all of this data
could be traveling on a public line in the CLEAR. You will need to add some
error trapping, and a reference to ADO in your database to make it all work.

Good luck with your project.

--
Ron W
www.WorksRite.com
"janetb" <janetb@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:965A84D9-2744-4D27-BBE1-FBDD201D0B5A@xxxxxxxxxxxxxxxx
> I have an odbc connection to an sql database backend. Everything's
working
> fine. But, just for a small section of code, is it possible to modify the
> code below and connect to another sql database in another city for which I
> have an account and password?
>
> Dim mySql as string
> mySql="select email, name from dbo_table where eid=" & forms!myForm!eid
>
> Set db = CurrentDb() 'Probably need to change it here.....
> Set rs = db.OpenRecordset(mySql, dbOpenDynaset, dbSeeChanges)
> Do While Not rs.EOF
> strMsg = "This is a final reminder blah....." & _
> vbCrLf & Trim(rs("name"))
> DoCmd.SendObject acSendNoObject, , , strTo, strCC, , strSubject,
> strMsg, False
> rs.MoveNext
> rs.Close
> Loop
>
> DoCmd.Close
>


.



Relevant Pages

  • Re: HELP PLEASE ~ ???
    ... You mentioned that it went ahead and added a SQL ... SQL Server 2000 database for all my data. ... find the connectionString in the newly recreated SQLExpress database. ... The connection string specifies a local Sql Server Express instance ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Web Part and Access database
    ... I dont know if it is possible to connect to access,but you can download SQL ... Server Error in '/Webparts' Application. ... The connection string specifies a local Sql Server Express instance ... String user, String password, Boolean trusted, String connectionString) ...
    (microsoft.public.sharepoint.portalserver.development)
  • Re: Connection issues between .Net framwok and SQl Express 2005
    ... You will no longer need the database MDF file name in the connection string. ... simply attach the ASPNETDB.mdf to SQL Server permenantly, ... as USER INSTANCE on existing SQL Server Express, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Performance of ODBC
    ... if you have a software firewall; forward 1433/1434 to your server ... I've now created my own server with SQL Server 2005 Express, ... glitch concerns the Upsizing Wizard. ... I originally set up my ODBC connection via ...
    (microsoft.public.access.adp.sqlserver)
  • Re: SQL 2000 and MSDE/Express/Compact edition..
    ... What is does is downloads .Net Framework and SQL Server Express if they are not installed and then configures SQL Server as a subscriber. ... string DotNetFramework2Location = ... LogMe("Creation of Replication Account failed."); ...
    (microsoft.public.sqlserver.replication)