HOWTO: Creating a Connection to SQL Server Without a Datasource

Last reviewed: October 31, 1997
Article ID: Q155392
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b

SUMMARY

When creating a connection to access remote data, you can create a connection that does not require an ODBC datasource. Because this method does not require an existing ODBC datasource, you do not have to be concerned with setting up the datasource in the ODBC administrator. This simplifies the task of application distribution.

MORE INFORMATION

The following steps outline how to create a connection that does not require an ODBC datasource. The connection will be called CONNECT1, and it accesses a SQL Server backend with the following attributes:

   Server Name = SQL1
   Logon User ID = USER
   Logon Password = password
   DATABASE = pubs

You can create the connection either programmatically or using the Connection Designer. Both of these methods will be addressed.

Creating the Connection Programmatically

  1. Open a database in which to store the connection.

  2. Enter the following command in the Command window:

          CREATE CONNECTION CONNECT1 CONNSTRING "DRIVER={SQL Server};
    
             SERVER=SQL1;UID=USER;PWD=password;DATABASE=pubs"
    
       NOTE: You should enter this command on one line.
    
    

Creating the Connection Using the Connection Designer

  1. Open a database in which to store the connection.

  2. From the File menu, click New.

  3. Specify a new connection.

  4. In the Connection Designer, select the "Connection String" option button.

  5. Enter the following for the Connect String:

          DRIVER={SQL Server};SERVER=SQL1;UID=USER;PWD=password;DATABASE=pubs
    

  6. Close the Connection Designer, and save the connection as CONNECT1.

To test the connection, enter the following in the Command window:

   ?SQLConnect('CONNECT1')

A return value greater than zero indicates a successful connection.


Additional query words: DSNLESS
Keywords : FxinteropOdbc vfoxwin
Version : 3.0 3.0b
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.