I am experiencing difficulty connecting to SQL Server Management Studio 2017 using Microsoft Visual Studio ASP.Net. The function or component I am trying to build is to allow me to upload a .docx document into a SQL database. The upload functionality works
fine however the problem lies in connecting to and inserting the data into my SQL Server database.
first check that whether you can login with SQL Management studio or not.
if you are also not able to login then you can try to check whether username is correct or not.
following can be the reasons which cause this error.
Scenario 1: The login may be a SQL Server login but the server only accepts Windows AuthenticationScenario
2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL ServerScenario
3: The login may use Windows Authentication but the login is an unrecognized Windows principalReference:"Login
failed for user" error message when you log on to SQL Serverif
this not helps to solve the issue then try to create a new login with proper permission and try to make a test with it.let us know about the testing results.
so that we can try to provide you further suggestions , if needed.RegardsDeepak
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
In Sql Server, user accounts and credentials are set at the server level, not at the database level. When you deploy an SQL database, only the database info moves over. You need to connect to the Database Server in your deployed environment , set up the
username and password you want to use, and give the account appropriate permissions into the database.
Login failed for User is a general sql error message and may have several causes. So, first you have to make sure that the user exist on SQL Server , that the user is enabled, and has
access (mapped) to the correct database.
In most cases, just set "Integrated Security=False" and it will work.
Make sure that you have the Mixed-Mode authentication enabled and here is how to enable it.
Also, either one of three things you will need to do to correct this issue:
Add the user used by the worker process to the SQL database and assign the appropriate permissions.
Change the Connection String to use a predefined user name and password.
Change the Anonymous authentication credentials or the credentials used by the worker process.
None
0 Points
3 Posts
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Oct 30, 2017 03:51 PM|nf00038|LINK
I am experiencing difficulty connecting to SQL Server Management Studio 2017 using Microsoft Visual Studio ASP.Net. The function or component I am trying to build is to allow me to upload a .docx document into a SQL database. The upload functionality works fine however the problem lies in connecting to and inserting the data into my SQL Server database.
WebForm2
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm2.aspx.cs" Inherits="WebApplication2.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID ="txtfilename" runat="server"></asp:TextBox>
<br />
Select File
<asp:FileUpload ID ="FileUpload1" runat="server"/>
<br />
<asp:Button ID ="Button1" runat="server" Text="Convert" OnClick ="Button1_Click"/>
</div>
</form>
</body>
</html>
WebForm2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication2
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!FileUpload1.HasFile)
{
Response.Write("No file Selected"); return;
}
else
{
string filename = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string extension = System.IO.Path.GetExtension(filename);
string contentType = FileUpload1.PostedFile.ContentType;
HttpPostedFile file = FileUpload1.PostedFile;
byte[] document = new byte[file.ContentLength];
file.InputStream.Read(document, 0, file.ContentLength);
//Validations
if ((extension == ".pdf") || (extension == ".doc") || (extension == ".docx") || (extension == ".xls"))//extension
{
if (file.ContentLength <= 31457280)//size
{
//Insert the Data in the Table
using (System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection())
{
connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
connection.Open();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.Connection = connection;
string commandText = @"insert into Documents(Name_File,DisplayName,Extension,ContentType,FileData,FileSize,UploadDate) values(@Name_File,@DisplayName,@Extension,@ContentType,@FileData,@FileSize,getdate())";
cmd.CommandText = commandText;
cmd.CommandType = System.Data.CommandType.Text;
cmd.Parameters.Add("@Name_File", System.Data.SqlDbType.VarChar);
cmd.Parameters["@Name_File"].Value = filename;
cmd.Parameters.Add("@DisplayName", System.Data.SqlDbType.VarChar);
cmd.Parameters["@DisplayName"].Value = txtfilename.Text.Trim();
cmd.Parameters.Add("@Extension", System.Data.SqlDbType.VarChar);
cmd.Parameters["@Extension"].Value = extension;
cmd.Parameters.Add("@ContentType", System.Data.SqlDbType.VarChar);
cmd.Parameters["@ContentType"].Value = contentType;
cmd.Parameters.Add("@FileData", System.Data.SqlDbType.VarBinary);
cmd.Parameters["@FileData"].Value = document;
cmd.Parameters.Add("@FileSize", System.Data.SqlDbType.BigInt);
cmd.Parameters["@FileSize"].Value = document.Length;
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
Response.Write("Data has been Added");
}
}
else
{ Response.Write("Inavlid File size"); return; }
}
else
{
Response.Write("Inavlid File"); return;
}
}
}
}
public partial class WebForm1
{
/// <summary>
/// txtfilename control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.TextBox txtfilename;
/// <summary>
/// FileUpload1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.FileUpload FileUpload1;
/// <summary>
/// Button1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button Button1;
}
}
Web Config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="ida:ClientId" value="591e3795-af82-435b-860e-83fa243f5fd1" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
<add key="ida:Domain" value="inspiredintelligencesolutions.com" />
<add key="ida:TenantId" value="bb0e43ab-d1c9-42e2-8810-7e60cf650b62" />
<add key="ida:PostLogoutRedirectUri" value="https://localhost:44341/" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1" />
<httpModules>
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
</httpModules>
</system.web>
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
<validation validateIntegratedModeConfiguration="false" />
<modules>
<remove name="TelemetryCorrelationHttpModule" />
<add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
<system.diagnostics>
<trace autoflush="true" indentsize="0">
<listeners>
<add name="myAppInsightsListener" type="Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener, Microsoft.ApplicationInsights.TraceListener" />
</listeners>
</trace>
</system.diagnostics>
<connectionStrings>
<add
name="ConnectionString"
connectionString="Data Source=IIS1\MSSQLSERVER01;Initial Catalog=InspiredIntelligence_FactDB;Persist Security Info=True;Pooling=False;User ID=IIS1\Neil;Password=*****;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
All-Star
48510 Points
18071 Posts
Re: Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Oct 30, 2017 04:04 PM|PatriceSc|LINK
Hi,
What is the exact name of your SQL Server account? Could it be "Neil" rather than just "IIS1\Neil" which seems to include your server name?
None
0 Points
3 Posts
Re: Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Oct 30, 2017 04:06 PM|nf00038|LINK
The username is IIS1\Neil. I have checked this user has permissions to my SQL database.
None
0 Points
3 Posts
Re: Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Oct 30, 2017 04:14 PM|nf00038|LINK
Contributor
2990 Points
1210 Posts
Re: Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Oct 31, 2017 07:22 AM|Deepak Panchal|LINK
Hi nf00038,
first check that whether you can login with SQL Management studio or not.
if you are also not able to login then you can try to check whether username is correct or not.
following can be the reasons which cause this error.
Scenario 1: The login may be a SQL Server login but the server only accepts Windows AuthenticationScenario 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL ServerScenario 3: The login may use Windows Authentication but the login is an unrecognized Windows principalReference:"Login failed for user" error message when you log on to SQL Serverif this not helps to solve the issue then try to create a new login with proper permission and try to make a test with it.let us know about the testing results. so that we can try to provide you further suggestions , if needed.RegardsDeepak
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
None
0 Points
14 Posts
Re: Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'IIS1\Neil'.
Feb 17, 2020 05:03 AM|EvanChatter|LINK
In Sql Server, user accounts and credentials are set at the server level, not at the database level. When you deploy an SQL database, only the database info moves over. You need to connect to the Database Server in your deployed environment , set up the username and password you want to use, and give the account appropriate permissions into the database. Login failed for User is a general sql error message and may have several causes. So, first you have to make sure that the user exist on SQL Server , that the user is enabled, and has access (mapped) to the correct database.
Also, either one of three things you will need to do to correct this issue: