Error: Incorrect syntax near the keyword ‘top’


Error: Incorrect syntax near the keyword ‘top’

Description: Syntax error.

Incorrect syntax near the keyword ‘top’


select col top 1 * from table1

Incorrect syntax near the keyword ‘from’


select top 1 from table1

etc…

Solution: Correct the syntax.


select top 1 * from table1

Error: In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.


Error: In order to run a trace against SQL Server you must be a member of sysadmin fixed server role or have the ALTER TRACE permission.

Description: When try to run the SQL Server Profiler using less privileged or minimal permissions credentials, this exception throws.

Solution: Provide ALTER TRACE permission for the particular user. Other ways are by providing, the user sysadmin fixed server role access which is not advised unless required.

 USE master
 GO
 GRANT ALTER TRACE TO user1
 GO

REVOKE the access

 USE master
 GO
 REVOKE ALTER TRACE FROM user1
 GO

Another way to grant rights, login with sysadmin login then open SSMS

~~ Open Security then Logins
~~ Right click on the login name and click Properties
~~ Securables tab
~~ Click Search to Select the instance that required permissions
~~ Under Explicit tab
~~ Select the check box ALTER trace permission and Click OK.

Error: Must declare the scalar variable “”.


Error: Must declare the scalar variable “”.

Description: An SQL Server exception which occur when a local variable being used within a script, function or Stored Procedure that is not declared using the DECLARE statement.

Solution: Declare the variable using the DECLARE statement.


DECLARE @FirstName NVARCHAR(25);

Error: Object cannot be cast from DBNull to other types.


Error: Object cannot be cast from DBNull to other types.

Description: An invalid cast exception, when trying to convert a nonexistent value of table column to other types.

Solution: Use DBNull.Value to validate the column having a valid value or not.


if (!DBNull.Value.Equals(row[FirstName]))
{
  return Convert.ToString(row[FirstName]);
}

Error: The build must be stopped before the solution can be closed.


Error: The build must be stopped before the solution can be closed.

Description: When attempt to close Visual Studio solution or project while the build is running the exception windows throws up.

Solution: First stop the build or kill the process devenv.exe (if the solution got crashed) and then close the solution.

Error: Unable to connect to the Database. A network-related or instance-specific error occurred while establishing a connection to SQL Server.


Error: Unable to connect to the Database.

Description: While trying or establishing a database connection and the connectivity to the database is not configured properly then this error occurs. More exception details as followed.

Exception Message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (-1)

Solution:

  1. Check whether TCP/IP in SQL Server Configuration is enabled or not.
  2. Ping the server name from command prompt. If no reply from server, then network connection to the server should be configured or enabled.
  3. Using Telnet command, we can check the port is opened or not, if not open the port.
  4. Check whether firewall is blocking the server port.
  5. Check any antivirus is blocking the server.
  6. Check the database name, user name and password using is correct or not.
  7. Check the required SQL Services (SQL Server Browser etc) account are running or not.
  8. Check your LAN network having connectivity issues.
  9. Use port number along with data source. e.g server name/server name, port number.
  10. Try creating alias in SQL Server Configuration.
  11. Try to connect the database through Visual Studio.
  12. Try using Database Server IP address as Server Name with or without port number.

How-to-Generate-or-find-Connection-String-from-Visual-Studio

Error: 404 – File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.


Error: 404 – File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Description: An HTTP Internal Server error thrown by Internet Information Services (IIS) when requested for an ASP.NET or ASP page etc. This can be of many reasons like, file or file path trying to access does not exists, or file name got renamed, the Virtual Directory wrongly mapped etc.

Solution: Check the file trying to access exists or not in correct path or location. Check the file path configured or able to access correctly. Check the Virtual Directory configured correctly and proper permissions given. Check the files extensions etc.