안녕하세요 선생님, 이번에 nextjs 강의를 끝내고 관계형 데이터베이스를 한번 써보면 좋겠다 해서 마이크로소프트 sql server를 사용해서
웹 사이트를 만들어보았습니다. 인증방식은 sql authentication으로 잘 인증되는거 확인했고, npm run start로 production 웹사이트도 잘
작동하는걸 확인했습니다. 그 후 netlify에 배포해봤는데, 데이터베이스에 못하는걸 확인했습니다. 처음에 mssqlnodev8 드라이버를 사용
했는데, 윈도우 전용 드라이버이기 때문에 리눅스 운영체제에서 문제가 있을 수 있대서, 드라이버 없이 npm mssql 패키지만 사용했는데
여전히 DB에 접근하지 못하는거같습니다.
간단한 Junk api 소스 코드입니다. import sql from 'mssql';
import sqlConfig from 'util/dbConfigSQL';
export default async function handler(req, res) {
if(req.method == "GET") {
try {
// Connect to the database
await sql.connect(sqlConfig);
// SQL query
const result = await sql.query`SELECT * FROM products`;
// Print results
console.dir(result);
res.status(200).json(result);
} catch (err) {
// Handle errors
console.error('Error trying to connect:', err);
} finally {
// Close the connection when finished
await sql.close();
}
}else {
// GET 이외의 메소드 요청 처리
res.status(405).json({ error: 'Method not allowed' });
}
}
junk11이라는 주소로 들어가면 products 테이블에 있는 데이터들을 줘야하는데, 주지 않더군요.. 환경 변수도 잘 작성해봤지만 작동하지 않는거같습니다.
대학교 교수님이 gpt한테 물어보라는데 답이 매일 다르더군요..