admin管理员组文章数量:1310283
I am building a nextjs self project with API routes defined in it and using the mssql
npm package to write queries in the API route to fetch and modify data from the database. My project works perfect locally but having issue after deploying it on vercel the UI renders but none of the API's work in order to fetch information from the SQL Server database.
This is my database connection function which ensures I am connected with my database through connection string:
import sql from "mssql";
import connectionString from "./database";
let connectionPool = null;
const dbConnect = async () => {
if (!connectionPool) {
try {
connectionPool = await sql.connect(connectionString);
console.log("Connected successfully to the database");
} catch (error) {
console.error("Error while connecting to the database:", error.message);
throw error;
}
}
return connectionPool;
};
export default dbConnect;
and this is my connection string and I have added all the env variables in Vercel env while deploying as key value pairs
const connectionString = {
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
server: process.env.SERVER_NAME,
database: process.env.DB_NAME,
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000,
},
options: {
encrypt: false,
trustServerCertificate: true
},
};
export default connectionString;
when I checked my vercel logs after registering a user through ui i got this
Error while connecting to the database: getaddrinfo EBUSY ayaanshaikh"
Error while registering user: Error [ConnectionError]: getaddrinfo EBUSY ayaanshaikh
at <unknown> (/var/task/todolist/.next/server/chunks/344.js:76:290113)
at H.t (/var/task/todolist/.next/server/chunks/344.js:76:78788)
at H.emit (/var/task/todolist/.next/server/chunks/344.js:76:78979)
at <unknown> (/var/task/todolist/.next/server/chunks/344.js:76:79583) {
code: 'EINSTLOOKUP',
originalError: Error: getaddrinfo EBUSY ayaanshaikh
at <unknown> (/var/task/todolist/.next/server/chunks/344.js:76:79598) {
code: 'EINSTLOOKUP',
[cause]: [Error: getaddrinfo EBUSY ayaanshaikh] {
errno: -16,
code: 'EBUSY',
syscall: 'getaddrinfo',
hostname: 'ayaanshaikh'
}
}
}
I have tried asking chatgpt but no help was provided please guide me through this.
版权声明:本文标题:Next.js API routes with SQL Server database work locally but fail after deploying to Vercel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741835210a2400175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论