Datagrip连接SQLServer Connecting DataGrip to MS SQL Server

Connecting DataGrip to MS SQL Server

Posted on June 21, 2016 by Maksim Sobolevskiy

Some specific needs of SQL developers like connecting to SQL Server from OSX and even using Windows authentication can be covered by DataGrip. Since releasing DataGrip, we’ve received lots of comments about connecting to SQL Server. It appears it’s not straightforward as with other databases, requiring a couple of extra steps beforehand. Here is a small guide describing the main problems you may face and how to solve them.

First, ensure that important options in SQL Server Configuration Manager are configured correctly. Make sure the SQL Server Browser is running:

SQLServer Browser

TCP/IP connections need to be enabled:

tcp

To know the port for the connection just click on TCP/IP. In our case, it’s default port 1433.

Port

If you end up changing anything, restart the server. For most situations, this will resolve connection problems, your server will accept remote connections and you are ready to go. If you still have problems, it could be that TCP port needs to be adjusted or the remote connection to SQL server needs to be enabled in its settings. This tutorial will walk you through it, but we’ll also describe the process here.

Invoke Database View by pressing Alt/Cmd+1 and create a new data source with the appropriate driver. If you use a Microsoft driver, note that it supports SQL Server 2008 and later versions. Here we’ll assume it’s the jTds driver.

NewDataSource

If you have no driver, download it by clicking the link.

Download drivers

Then enter the host name, the instance name and the credentials. Remember that DataGrip offers completion for host, instance and database names (Ctrl/Cmd+Space), but the name of the database is optional. For those who are used to the SSMS interface, let’s compare the connection windows.

Connect SSMS Compare

If the port number conflicts with the instance name, in the jTds driver, the instance name will take precedence over the port number, while the opposite will happen in the Microsoft driver. To avoid confusion, simply remove the port number. If you strongly wish to specify the port number, click the Auto-set button (located to the right of the Instance field) to have the port number set automatically. But remember that the port number can be changed in case you restart the server.

PortConflict

If you need to use Windows authentication, only Microsoft driver will let you do it.

Windows auth

The other way to connect to the server with Windows authentication is to use domain authentication of jTds driver, which lets you connect from any other machine. What is notable, it works on any OS. To do this, go to the Advanced tab of data source properties, set USENTLMV2 to true and specify the domain name in the DOMAIN field.

AdvancedForWindows

Then enter your Windows credentials in user/password fields and click Test Connection.

If you want to check which particular databases or schemas are shown in the database view, go to the Schemas tab in Data source properties:

SchemasTab

In case you are already using DataGrip 2016.2 EAP, use More Schemas… in the database view:

MoreSChemas

All selected databases will appear in the database view. This is how it looks in SQL Server Management Studio:

Databases

And here’s how it looks in DataGrip:

ManyDBSCurrent

That’s it! If you are experiencing any other problems, please tweet @ us or create an issue in our youtrack.

Your DataGrip Team

The Drive to Develop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 JSP 连接SQL Server 数据库,需要完成以下几个步骤: 1. 下载 Microsoft JDBC 驱动程序:访问 Microsoft 官方网站,下载适用于 SQL Server 的 JDBC 驱动程序,选择最新版本的 JDBC 驱动程序。 2. 将 JDBC 驱动程序添加到 CLASSPATH:将下载的 JDBC 驱动程序的 jar 文件复制到您的项目中,并将其添加到 CLASSPATH 中。 3. 在 JSP 页面中编写连接代码:在 JSP 页面中编写连接SQL Server 数据库的代码,可以使用以下代码示例: ```java <%@ page import="java.sql.*" %> <% String url = "jdbc:sqlserver://localhost:1433;databaseName=mydatabase"; String username = "username"; String password = "password"; Connection con = null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = DriverManager.getConnection(url, username, password); out.println("Connected to database successfully!"); } catch (Exception e) { out.println("Error connecting to database: " + e.getMessage()); } finally { try { if (con != null) con.close(); } catch (SQLException e) { out.println("Error closing connection: " + e.getMessage()); } } %> ``` 在上面的代码中,将 `url`、`username` 和 `password` 分别替换为您的 SQL Server 数据库的连接字符串、用户名和密码。 4. 测试连接:运行 JSP 页面,如果一切正常,将看到 "Connected to database successfully!" 的消息。 注意:使用 JSP 直接连接数据库存在安全风险,建议使用 JPA 或 ORM 框架进行数据库访问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值