Could not find a declaration for module 'mssql/msnodesqlv8' - sql-server

developing API using typescript in node.js
importing the below package to use sql server database
import sql from "mssql/msnodesqlv8";
but this giving me the following error
Could not find a declaration for module 'mssql/msnodesqlv8'
implicitly has an any type. if it exists or add a new declaration (.d.ts) file
containing declare module 'mssql'
I have this declaration in almost every routing file and facing this ugly red color on every file showing me error because of this declaration.
The following packages are installed in my project
"msnodesqlv8": "^0.6.6",
"mssql": "^4.1.0",
"#types/mssql": "^4.0.7",
Any suggestions to get out of this?

I fixed this issue by running :
npm install mssql & npm install msnodesqlv8
my package.json look like this :
https://i.stack.imgur.com/7wMTk.png
connect to SQL Server and run query :
const connection = new sql.ConnectionPool({
server: *ServerName* ,
driver: 'msnodesqlv8',
options: {
trustedConnection: true
}})
connection.connect().then(()=> {
connection.query(`*Query*`,(err,result)=>{
if(err){
res.send(err);
}
else{
res.json(result)
}
})
})

Related

Can't figure out how to fix Error: P1001: Can't reach database server at `localhost`:`5432`

I am running into the error:
Error: P1001: Can't reach database server atlocalhost:5432`
Please make sure your database server is running at localhost:5432.
`
I am trying to use the command "npx prisma migrate dev" however it continueously throws the error stated above.
schema.prisma file:
datasource db { provider = "postgresql" url = env("DATABASE_URL") }
.env file:
DATABASE_URL="postgresql://[username]:[password]#localhost:5432/[db]?schema=public"
Any help or insight as to how to fix this error would be greatly appreciated!

import pyodbc, No module name 'pyodbc'

I am pretty new to all this so please bear with me.
I am trying to deploy my code in AWS Elastic-Bean Stalk and my code has pyodbc package to fetch data from the database. The database is deployed on Microsoft Azure and it's connected to the code. After deploying code to Elastic-bean it's showing error
import pyodbc no module name pyodbc
I have checked the requirement.txt file and it has latest version of pyodbc package. I did update all the versions that I have imported. There are students who have done the same process(database on Azure and Code on AWS ElasticBean Stack) and its running fine. My code is running perfectly fine on the local machine.
any leads ???
The install pyodbc may be failing, thus its not getting installed.
The reason is, that on EB for Amazon Linux 2, you need to have gcc-c++ and unixODBC-devel as prerequisites for pyodbc.
Thus in your .ebextentaions you can add a config file .ebextentaions/10_packages.config with the content of:
packages:
yum:
gcc-c++: []
unixODBC-devel: []

Using Scala to Write a DF to a SQL Server Table

I'm trying to use the code below.
import com.microsoft.azure.sqldb.spark.config.Config
import com.microsoft.azure.sqldb.spark.connect._
// Aquire a DataFrame collection (val collection)
val config = Config(Map(
"url" -> "mysqlserver.database.windows.net",
"databaseName" -> "MyDatabase",
"dbTable" -> "dbo.Clients"
"user" -> "username",
"password" -> "*********"
))
import org.apache.spark.sql.SaveMode
collection.write.mode(SaveMode.Append).sqlDB(config)
The script is from this link.
https://github.com/Azure/azure-sqldb-spark
I'm running this in a databricks environment. I'm getting these errors:
command-836397363127942:5: error: object sqlDB is not a member of package com.microsoft.azure
import com.microsoft.azure.sqlDB.spark.connect._
^
command-836397363127942:4: error: object sqlDB is not a member of package com.microsoft.azure
import com.microsoft.azure.sqlDB.spark.config.Config
^
command-836397363127942:7: error: not found: value Config
val bulkCopyConfig = Config(Map(
^
command-836397363127942:18: error: value sqlDB is not a member of org.apache.spark.sql.DataFrameWriter[org.apache.spark.sql.Row]
df.write.mode(SaveMode.Append).sqlDB(bulkCopyConfig)
I'm guessing that some kind of library is not installed correctly. I Googled for an answer, but didn't find anything useful. Any idea how to make this work? Thanks.
If you are getting the sqldb error means all other support libraries already imported to your notebook and only the latest JAR with dependencies are missing.
As per the repro, I got the same error message as shown above:
After bit of research, I had found that you will experience this error due to missing JAR with dependencies.
To resolve this issue, you need to download the JAR file from here: https://search.maven.org/artifact/com.microsoft.azure/azure-sqldb-spark/1.0.2/jar
After downloaded the jar file, upload the JAR library into the cluster and install it.
Note: After installing both the libraries, make sure to restart the cluster.
Now, you will be able to run the command successfully.
I think you have missed the library
If your using Maven Build Add the following library in pom.xml
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-sqldb-spark</artifactId>
<version>1.0.2</version>
</dependency>
If your using SBT Build Add the following library in build.sbt
libraryDependencies += "com.microsoft.azure" % "azure-sqldb-spark" % "1.0.2"
Have you imported and installed the library in DataBricks?
I found it easiest to import the library using Maven. See this answer: How to install a library on a databricks cluster using some command in the notebook?
Note: You need to install the Library on your cluster and then restart the cluster before you can use it.

How can I run React in Development mode with .NetCore in IIS?

I've used the Visual Studio template for .NetCore/React web app. By default, it runs in Development mode using IIS Express. However, if I set up a site in IIS, and a launch profile, I get an error in the browser:
AggregateException: One or more errors occurred. (One or more errors
occurred. (The NPM script 'start' exited without indicating that the
create-react-app server was listening for requests. The error output
was: Error: EPERM: operation not permitted, mkdir
'C:\Windows\system32\config\systemprofile\AppData\Roaming\npm'
My launchSettings.json has the following for the IIS profile:
"IIS": {
"commandName": "IIS",
"launchBrowser": true,
"launchUrl": "http://localhost",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
From the error, it looks like it may be a permission issue that I need to have the IIS app pool running under, but I can't find any documentation that tells me anything about that.
What am I missing? Again, this is an otherwise unmodified project from the template. The Startup.cs is running React as would be expected with:
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{ spa.UseReactDevelopmentServer(npmScript: "start"); }
});
According to your description, I suggest you could firstly modify the IIS default application pool's identity to make sure it has the permission to run npm.
I suggest you could follow below steps:
1.Open the IIS management console, locate the application pool,find the default application pool and click the advanced setting.
Find the identity setting and modify the build-in account to localsystem
Then I suggest you could add the npm path in the system environment.
Go to Control Panel\System and Security\System and find advanced system settings
2.Click environment variable
3.Find the path inside the system variable and add the npm path as below:
C:\Users\{username}\AppData\Roaming\npm

Using node-sqlserver or node-mssql under Azure

I'm trying to connect to a database on Azure using node-mssql. My development system is Windows 7 and I have had no success at all getting node-sqlserver to install via WebMatrix.
My question is two part: Firstly is there any reason that even when I follow the instructions from Microsoft that I get errors with node-sqlserver? Trying the naive approach using NPM inside WebMatrix I get the following error:
An error occurred.
"C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "node-sqlserver" "--json"
Exit status 1
Failed at the node-sqlserver#0.1.0 install script.
This is most likely a problem with the node-sqlserver package,
not with npm itself.
Tell the author that this fails on your system:
node-gyp rebuild
You can get their info via:
npm owner ls node-sqlserver
There is likely additional logging output above.
Failed: npm reported an error.
NodeNpm.NpmException: Failed: npm reported an error.
at NodeNpm.NpmApi.Install(INpmPackage package)
at Microsoft.WebMatrix.NpmGallery.CachingPackageManger.InstallPackage(INpmPackage package)
at Microsoft.WebMatrix.NpmGallery.PackageViewModel.Install()
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
The machine has VS2012 Professional installed.
The second part of my question is, is there any reason why using node-mssql won't work under Azure? I simply get a failed connection error, even though I've verified the details several times (substituted placeholders for actual values below):
var config = {
user: '{username}',
password: '{password}',
server: 'tcp:{server}.database.windows.net',
database: '{database}'
}
I get the following error:
{"name":"ConnectionError","message":"connection to tcp:{server}.database.windows.net:1433 >- failed Error: getaddrinfo ENOTFOUND"}
I realise that node-sqlserver is the best way to do it under Azure but I've tried for a couple of days with no success. Is there anything obvious I am missing?
1) You can solve it by downloading precompiled node-sqlserver driver from this repo. I was not able to compile sources on my machine even with all dev dependencies installed as well.
2) node-mssql module use three different drivers to communicate with sql server. Your config doesn't specify any driver, so the default one is used - Tedious. You must change your config to make it work correctly:
var config = {
user: '{username}',
password: '{password}',
server: '{server}.database.windows.net', // simply remove "tcp:"
database: '{database}'
}
There is also an option to use node-mssql with node-sqlserver but to make it work, you have to install compiled node-sqlserver driver manually. Config should look like this:
var config = {
driver: 'msnodesql',
user: '{username}',
password: '{password}',
server: 'tcp:{server}.database.windows.net',
database: '{database}'
}
I was using SQL Azure from Node.js last year when the module was named node-sqlserver so my answer might not work.
Ref your first problem, node-mssql should need to be compiled through node-gyp and C++ during NPM installation. So you'd better check if you have C++ compiler installed. When I was installing it told me I need VS2010 C++. Not sure if you need it now, or any later version. You can run npm install node-mssql from command window and you should get a log file if it failed, should be npm-error.log or something similar.
Ref your second problem, when I was using this module I use connection string. Could you double check your username was specified in format user#server. Also double check if your SQL Azure firewall was opened for other cloud services.

Resources