Excel Connect To Sql Database

  1. Using Sql In Vba Excel
  2. Connecting Excel To Sql Database Using Vba
  3. Excel Vba Code To Connect To Sql Database

Use Excel's Get & Transform (Power Query) experience to connect to a SQL Server database.

Newer versionsOffice 2010 – 20132007
  1. Click on the Data tab, then Get Data > From Database > From SQL Server Database. If you don't see the Get Data button, click New Query > From Database > From SQL Server Database.

  2. In the Microsoft SQL Database dialog box, specify the SQL Server to connect to in the Server Name box. Optionally, you can specify a Database Name as well.

  3. If you want to import data using a native database query, specify your query in the SQL Statement box. For more information, see Import Data from Database using Native Database Query.

  4. Select OK.

  5. Select the authentication mode to connect to the SQL Server database.

    1. Windows: This is the default selection. Select this if you want to connect using Windows authentication.

    2. Database: Select this if you want to connect using SQL Server authentication. After you select this, specify a user name and password to connect to your SQL Server instance.

  6. By default, the Encrypt connection check box is selected to signify that Power Query connects to your database using an encrypted connection. If you do not want to connect using an encrypted connection, clear this check box, and then click Connect.

    If a connection to your SQL Server is not established using an encrypted connection, Power Query prompts you to connect using an unencrypted connection. Click OK in the message to connect using an unencrypted connection.

Formula Example

You can also use the Query Editor to write formulas for Power Query.

  1. In the Power Query ribbon tab, click From Database > From SQL Server Database.

  2. In the Microsoft SQL Database dialog box, specify the SQL Server to connect to in the Server Name box. Optionally, you can specify a Database Name as well.

  3. If you want to import data using a native database query, specify your query in the SQL Statement box. For more information, see Import Data from Database using Native Database Query.

  4. Select OK.

  5. Select the authentication mode to connect to the SQL Server database.

    1. Windows: This is the default selection. Select this if you want to connect using Windows authentication.

    2. Database: Select this if you want to connect using SQL Server authentication. After you select this, specify a user name and password to connect to your SQL Server instance.

  6. By default, the Encrypt connection check box is selected to signify that Power Query connects to your database using an encrypted connection. If you do not want to connect using an encrypted connection, clear this check box, and then click Connect.

    If a connection to your SQL Server is not established using an encrypted connection, Power Query prompts you to connect using an unencrypted connection. Click OK in the message to connect using an unencrypted connection.

Using Sql In Vba Excel

Formula Example

Nov 28, 2017 - I tried using the data, get data, sql server option. It does not understand azure sql database. If I use the data, new query, azure sql database. You can use an Office Data Connection (.odc) file to connect to a Microsoft SQL Server database from a Microsoft Excel file. SQL Server is a full-featured, relational database program that is designed for enterprise-wide data solutions that require optimum performance, availability, scalability, and security.

Connecting Excel To Sql Database Using Vba

How can the answer be improved?

You can also use the Query Editor to write formulas for Power Query.

The Get & Transform experience was not available in Excel 2007, so you can use an Office Data Connection (.odc) file to connect to a Microsoft SQL Server database from an Excel 2007 workbook. SQL Server is a full-featured, relational database program that is designed for enterprise-wide data solutions that require optimum performance, availability, scalability, and security.

  1. On the Data tab, in the Get External Data group, click From Other Sources, and then click From SQL Server.

    The Data Connection Wizard starts. This wizard has three pages.

    Page 1: Connect to Database Server

  2. In step 1, type the name of the SQL Server computer in the Server name box.

  3. In step 2, under Log on credentials, do one of the following:

    • To use your current Microsoft Windows user name and password, click Use Windows Authentication.

    • To enter a database user name and password, click Use the following User Name and Password, and then type your user name and password in the corresponding User Name and Password boxes.

      Security Note:

      • Use strong passwords that combine uppercase and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: house1. Passwords should be 8 or more characters in length. A pass phrase that uses 14 or more characters is better.

      • It is critical that you remember your password. If you forget your password, Microsoft cannot retrieve it. Store the passwords that you write down in a secure place away from the information that they help protect.

      Page 2: Select Database and Table

  4. Under Select the database that contains the data you want, select a database. Under Connect to a specific table, select a specific table or view.

    Alternatively, you can clear the Connect to a specific table check box, so that other users who use this connection file will be prompted for the list of tables and views.

    Blade max wipers. Page 3: Save Data Connection File and Finish

  5. Optionally, in the File Name box, revise the suggested file name. Click Browse to change the default file location (My Data Sources).

  6. Optionally, type a description of the file, a friendly name, and common search words in the Description, Friendly Name, and Search Keywords boxes.

  7. To ensure that the connection file is always used when the data is updated, click the Always attempt to use this file to refresh this data check box. This check box ensures that updates to the connection file will always be used by all workbooks that use that connection file.

  8. To specify how the external data source of a PivotTable report is accessed if the workbook is saved to Excel Services and is opened by using Excel Services, click Authentication Settings, and then select one of the following options to log on to the data source:

    • Windows Authentication Select this option to use the Windows user name and password of the current user. This is the most secure method, but it can affect performance when many users are connected to the server.

    • SSO Select this option to use Single Sign On (SSO), and then enter the appropriate identification string in the SSO ID box. A site administrator can configure a Windows SharePoint Services site to use a Single Sign On database in which a user name and password can be stored. This method can be the most efficient when many users are connected to the server.

    • None Select this option to save the user name and password in the connection file.

      Security Note: Avoid saving logon information when connecting to data sources. This information may be stored as plain text, and a malicious user could access the information to compromise the security of the data source.

      Note: The authentication setting is used only by Excel Services, and not by Excel.

  9. Click OK.

  10. Click Finish to close the Data Connection Wizard.

    The Import Data dialog box is displayed.

  11. Under Select how you want to view this data in your workbook, do one of the following:

    • To create an Excel table, click Table (this is the default).

    • To create a PivotTable report, click PivotTable Report.

    • To create a PivotChart and PivotTable report, click PivotChart and PivotTable Report.

      Note: The Only Create Connection option is available only for an OLAP database.

  12. Under Where do you want to put the data?, do one of the following:

    • To place the data in an existing worksheet, select Existing worksheet, and then type the name of the first cell in the range of cells where you want to locate the data.

      Alternatively, click Collapse Dialog to temporarily collapse the dialog box, select the beginning cell on the worksheet, and then click Expand Dialog .

    • To place the data in a new worksheet starting at cell A1, click New worksheet.

  13. Optionally, you can change the connection properties (and also change the connection file) by clicking Properties, making your changes in the Connection Properties dialog box, and then clicking OK.

    For more information, see Connection properties.

Need more help?

You can always ask an expert in the Excel Tech Community, get support in the Answers community, or suggest a new feature or improvement on Excel User Voice.

Excel Vba Code To Connect To Sql Database

See Also

Hi,

The Excel spreadsheet that is connected to an SQL database with an Excel query has started to go very slowly. It takes ages at the 'Connecting to data source' stage. Once connected the read is ok.

What could have caused the connecting stage to start going so slow?

The connection string is:

'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=IRIS_dc1;Data Source=hw-core-db04;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=HW-CORE-TS48;Use Encryption for Data=False;Tag with column collation when possible=False'

String

and the SQL command is:

'SELECT Practice.ibvClient.ClientId, Practice.ibvClient.ClientName, Practice.ibvClient.ClientType, Practice.ibvClient.ClientCategory3Desc, Practice.ibvClient.ClientCategory3, Practice.ibvClient.ClientPartner,
Practice.ibvClient.ClientPartnerName, Practice.ibvClient.ClientCategory6, Practice.ibvClient.ClientCategory6Desc, Practice.ibvWIPClientBalanceEOP.Year, Practice.ibvWIPClientBalanceEOP.Balance,

Practice.ibvWIPClientBalanceEOP.Period, Practice.ibvClient.ClientManager, Practice.ibvClient.ClientManagerName
FROM Practice.ibvClient LEFT OUTER JOIN
Practice.ibvWIPClientBalanceEOP ON Practice.ibvClient.ClientCatsObjectType = Practice.ibvWIPClientBalanceEOP.ClientObjectType AND
Practice.ibvClient.ClientCatsInternalId = Practice.ibvWIPClientBalanceEOP.ClientInternalId'

As far as I can see nothing has changed. Thank you for your help.

Best wishes

Ros

Comments are closed.