Skip to content
Advertisement

SQL Server : delete user

I’m trying to write a query to delete a user registration from my SQL Server database, but when I try to delete a user, I get this error:

System.InvalidOperationException: ‘ExecuteReader: Connection property has not been initialized.’

My code:

Advertisement

Answer

You need to open connection before you can create a command. i.e.

However your current code contains SQL Injection. You should not concatenate strings go get your SQL. You should use parameters. See this answer for better explanation about the application.

Also it is never a good practice to store passwords in plain text. Ever. You should store hash of password only and compare the hashes rather than plain-text. Read this answer for reference. And more background info on why you should hash

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement