最近搭建springboot項目開發環境,數據庫連的是sql server,遇到許多問題在此記錄一下。
1、sql server安裝教程
參考:https://www.bilibili.com/opus/944736210624970769
2、sql server導出、導入數據庫
參考:https://blog.csdn.net/noriyyds/article/details/130814064
3、用Windows身份驗證方式登錄SQL Server Management Studio添加一個新的用戶并設置密碼,密碼要足夠復雜才可。
– 給用戶分配角色
CREATE USER userName FOR LOGIN userName ;
ALTER ROLE db_datareader ADD MEMBER userName;
ALTER ROLE db_datawriter ADD MEMBER userName;
4、application.yml配置
spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriverdruid:master:url: jdbc:sqlserver://XXX.XXX.XXX.XXX:1433;databaseName=nrid;sendStringParametersAsUnicode=true;encrypt=true;trustServerCertificate=trueusername: userNamepassword: userPassWord
5、運行報錯和解決辦法
5.1后臺報錯:com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host XXX.XXX.XXX.XXX, port 1433 has failed. Error: “Connection timed out: no further information… Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.”.
解決方法:https://blog.csdn.net/weixin_47246285/article/details/130605313
5.2后臺報錯: Error querying database. Cause: com.microsoft.sqlserver.jdbc.SQLServerException: The SELECT permission was denied on the object ‘sys_job’, database ‘nrid’, schema ‘dbo’.
解決方法:用Windows身份驗證方式登錄SQL Server Management Studio執行語句
USE [YourDatabaseName];
GO
GRANT SELECT ON SCHEMA::dbo TO [YourUserName];
GO
然后把insert、update、delete權限都賦給新添加的用戶。