gpt4 book ai didi

javascript - React JS MSSQL 拒绝导入 mssql

转载 作者:行者123 更新时间:2023-11-29 19:03:31 30 4
gpt4 key购买 nike

我正在尝试导入 mssql 我有一个 js 文件,它自己可以正常工作,但我需要这样做,以便我可以从 react js 环境中调用该函数,而不仅仅是节点

import React, { Component } from 'react';

import TextInput from '../SmallBits/FormItems/TextInput';

import sql from 'mssql';
//or
var sql = require('mssql');

var dbConfig = {
server: 'localhost',
database: 'TestDB',
user: 'andy',
password: 'andy',
port: 1433
};

export default class LeftBox extends Component {
constructor(props){
super(props);
this.state = {
name: '',
forename: '',
surname: '',
caseID: '',
address: ''
}
this.handleSurnameChange = this.handleSurnameChange.bind(this);
this.handleForenameChange = this.handleForenameChange.bind(this);
this.handleCaseIDChange = this.handleCaseIDChange.bind(this);
this.handleAddressChange = this.handleAddressChange.bind(this);
}

loadEmployees() {
var dbConn = new sql.ConnectionPool(dbConfig);
dbConn.connect().then(function () {
var request = new sql.Request(dbConn);
request.query("select * from EmployeeTable").then(function (recordSet) {
console.log(recordSet);
return recordSet;
dbConn.close();
}).catch(function (err) {
console.log(err);
dbConn.close();
});
}).catch(function (err) {
console.log(err);
});
}

这就是顶部机器人中被调用的导入和 require 语句的所有代码给我同样的错误,模块未找到:无法解析 'C:\Users\wilsona.CHECKMATE\Desktop 中的 'mssql'\reactapp\Workspace\savvy-crm-test\src\components\Parts\Boxes' 即使 mssql 是全局安装的,我也应该在本地安装吗

最佳答案

这似乎类似于 Errors with node-mssql in a webpack-bundled React app

MSSQL server connection libraries are not client-side javascript libraries. There is absolutely no way you can make TCP SQL connections from a web browser, even if you wrote your own library.

For security reasons, you would never want to allow client-side access to the SQL Server. You need to spin up server-side environment (e.g. Node/Express) to expose an API to the client applications.

关于javascript - React JS MSSQL 拒绝导入 mssql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44828539/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com