I'm baffled, and am stuck, and have been for 2 hours now.
Here is my connection string:
<add name="yafnet" connectionString="Data Source=localhost;Initial Catalog=Scirra;User Id=Gullanian;Password=12345;" providerName="System.Data.SqlClient" />
And I get:
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'Gullanian'.
I've created the database 'Scirra'. I've also attempted to add a login, but nothing seems to work. Logging into SQL management via Windows Authentication is the only way I can gain access to my DB's.
Ideally I just want to create a user, and that user having full control of DB. So I can run scripts etc.
Here's a few details:
Microsoft SQL Server Management Studio 10.50.1600.1
Microsoft Data Access Components (MDAC) 6.1.7600.16385
Microsoft MSXML 3.0 6.0
Microsoft Internet Explorer 8.0.7600.16385
Microsoft .NET Framework 2.0.50727.4952
Operating System 6.1.7600
Idk why it says v2 for asp.net, all my application pools are set to 4.0.
You need to enable SQL Server authentication (will need a restart) or use Windows Authentication.
Related
I'm having problems connecting to an MSSQL database in an ASP.NET Web Forms application. The error I get the is the user corp\earth3 can't connect. earth3 is the name of the computer ... the logged in user is corp\earth (a domain administrator) which is what works when connecting to the database using MSSQL Management Studio. I'm building the web app on Windows 10 and its being deployed for production use on a Windows 2012 server (which has the same connection problem as the win10 machine).
I've tried each of the following in web.config. This works while connecting to other database instances on the db server, but not on this one.
<add key="sqlConnectString" value="Data Source=db01\pd; Initial Catalog=PDB; Trusted_Connection=Yes;"/>
<add key="sqlConnectString" value="Data Source=db01\pd; Initial Catalog=PDB; Integrated Security=SSPI;"/>
What am I doing wrong here? Why can't I connect to the db using corp\earth?
Thanks.
Modify the Identity in the application pool with a user that can connect to the database. Create a custom app pool if you don't want to make a change that would affect other web sites it uses.
I have an ASP.NET 4.0 application within which I need to forward the authentication to the database.
For the purposes of this request for assistance, lets call the web server "app1" and the database server "sql1".
The SQL2008R2 database service is running as a named instance "SQL2008R2" under a custom domain account "SqlServer". The server is running Windows Server 2008 R2 Enterprise Edition.
I have created an SPN for this...
setspn -a MSSQLSvc/sql1.mydomain.local:SQL2008R2 SqlServer
The ASP.NET application is running under an application pool using a custom domain account "WebApplicationUser", in Integrated Pipeline mode. It is currently running on my laptop running Windows 7 Enterprise, but will eventually be hosted on Windows Server 2008 R2 Standard Edition.
I have created 2 SPN's for the application (on the Windows 7 machine that I am currently running from)...
setspn -a http/app1 WebApplicationUser
setspn -a http/app1.mydomain.local WebApplicationUser
Within Active Directory users and Computers, I have selected the "WebApplicationUser" account and I have enabled constrained delegation to "MSSQLSvc/sql1.mydomain.local:SQL2008R2" using any protocol (I have also tried using Kerbero only).
The Application is setup in IIS 7.5 and the authentication is set to disable Anonymouse, Basic, Digest and Forms whilst enabling "ASP.NET Impersonation" and "Windows". The Windows authentication has "Extended protection" turned off and "Kernel-mode authentication" enabled. The providers are "Negotiate" and "NTLM" in that order.
The ASP.NET application uses EF, and the connection string is configured to use integrated security...
<connectionStrings>
<add name="MyContext"
connectionString="metadata=res://*/Data.MyModel.csdl|res://*/Data.MyModel.ssdl|res://*/Data.MyModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=sql1.mydomain.local\sql2008r2;Initial Catalog=MyDatabase;Persist Security Info=false;Integrated Security=True;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
My web config specifies both Windows authentication and impersonation, since I a using async pages, I have also enabled inpersonation policy flowing...
<runtime>
<alwaysFlowImpersonationPolicy enabled="true" />
</runtime>
<system.web>
<authentication mode="Windows" />
<identity impersonate="true" />
</system.web>
If I log on locally (on "web1") and browse to the application (using IE), this all works - but this does not involve the double hop that I am trying to resolve.
If I log on to another machine and then browse to the application using IE, or I browse from the local machine using FireFox, this does not work - note: FireFox does prompt me for the login details. The connection to the database fails with "Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'"
Unlike a lot of the articles (and here might be part of the problem), I am not using any custom code to impersonate the user. It is my understanding that the impersonation will be applied across the board to the application by the web.config settings above. All I do is to open the connection and then close it again when I am finished with it.
I have obviously missed a step (or two), but having looked at all of the documentation that I can find (and there has been a lot), I still cannot find what that step is. It does not help that 99% of the documentation that I can find is actually related to IIS6 and Windows 2003 but the principles should remain the same.
Has anybody suceeded in getting such a configuration to work on Windows 7 and/or Windows Server 2008?
Checklist for Double Hop issues {IIS and SQL Server}
http://blogs.technet.com/b/taraj/archive/2009/01/29/checklist-for-double-hop-issues-iis-and-sql-server.aspx
http://www.phishthis.com/2009/10/24/how-to-configure-ad-sql-and-iis-for-two-hop-kerberos-authentication-2/
http://support.microsoft.com/kb/810572
IIS to SQL Server kerberos auth issues
When you configure the SPNs for SQL Server, we have found that we need to include the PORT on which SQL Server listens (1433).
You should download and use Brian Booth's DelegConfig v2 tool to help you setup the correct configuration settings. http://blogs.iis.net/brian-murphy-booth/archive/2009/04/22/delegconfig-v2-beta.aspx
It will basically hold your hand the whole way through the process. We've found the tool to be invaluable.
I´m having trouble connecting to SQL Server 2008 R2 Express with Northwind database using ApplicationPoolIdentity in IIS 7.5, resulting in the following error message:
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. The connection will be closed.
notes:
I´m using Windows 7/VS 2010/IIS 7.5/SQL Server 2008 R2 Express (all in the same machine).
my site is using "ASP.NET v4.0" application pool;
ASP.NET v4.0 application pool is using ApplicationPoolIdentity as Identity;
the SQL Server 2008 R2 express has the Login "IIS APPPOOL\ASP.NETv4.0" with the server role sysadmin granted;
the Northwind database has the user "IIS APPPOOL\ASP.NET v4.0" configured with the following permitions: db_accessadmin, db_backupoperator, db_datareader, db_datawriter, db_ddladmin, db_securityadmin;
the w3wp.exe process is running with the user "IIS APPPOOL\ASP.NETv4.0"
I can see that the user profile folder is created (C:\Users\ASP.NET v4.0);
the same problem occurs using the application pool "DefaultAppPool".
If I change the ApplicationPoolIdentity user to another user that has rights to access the database it works.
Additional informations:
connection string:
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=NOTEBOOK\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
Could anyone help me to solve this issue?
Thanks in advice.
It looks like you're trying to use SQL Server Express's "user instancing" feature, i.e. your connection string looks like:
AttachDBFilename=|DataDirectory|xxxxxx.mdf;User Instance=true
This won't work for ApplicationPoolIdentity accounts in IIS7.5. For more information see this MS Knowledgebase article:
Problems with SQL Server Express user instancing and ASP.net Web Application Projects
Web applications built with Visual Studio 2005, Visual Studio 2008, or
Visual Studio 2010 and that rely on user instancing with either SQL
Server Express 2005 or SQL Server Express 2008 do not work with the
new application pool identity. These products were developed and
tested against application pools running with the older NETWORK
SERVICE account.
Also Microsoft discourage using this feature now:
This feature will be removed in a future version of Microsoft SQL
Server. Avoid using this feature in new development work, and plan to
modify applications that currently use this feature.
If you've not already done so, I would attach the database to SQL Express and use a regular SQL connection string instead, just like you'd do in a production environment. You may need to enable TCP/IP for your SQL Express instance using the SQL Server Configuration Manager if it's not already enabled:
And ensure that port 1433 is configured as well on the next tab of that dialogue.
I created an ASP.NET website with Visual Studio 2008 sp1 and in the code I use SQL connection to reach a data base in my SQL Server 2008. It all wiorks great but then I wanted to deploy the website in IIS7 (Windows 7) which was hell to discover how to do it-
(I added a virtual directory and converted it to an application and only then it didn't show me the error that I was getting before I copied it to inetpub\wwwroot and converted it to an application). After doing it I tried to run it from the IIS7 but it just keeps showing me an error that it gets in the command sqlconnection.open() which works great when I run the website from the Visual Studio. How do I resolve this?
I am using the following connection string: "Data SourceEDI-PC\SQLEXPRESS;Initial Catalog=SyncMaster;Integrated Security=True"
And my IIS7 is on the same computer as the SQL Server, so what exextly do I have to do to make it work?
Your connection string probably looks like this...
<add name="ConnectionString"
connectionString="Data Source=servername;
Initial Catalog=dbname;
Integrated Security=True"
providerName="System.Data.SqlClient" />
Which means it is using the windows account IIS runs under, NETWORK SERVICE, to connect. When you run from Visual Studio it uses your windows account which has access to the SQL server.
Create a sql user to use as a service account and specify that info in the connection string. This way it will try to connect using the same account that you created in both Visual Studio and IIS.
ie.
<add name="ConnectionString"
connectionString="Data Source=servername;
Initial Catalog=dbname;
Persist Security Info=True;
User ID=sqluser;
Password=sqruserpassword"
providerName="System.Data.SqlClient" />
When running in IIS7 (or any other IIS for that matter) the connection to sql server is made as the user that runs the application pool in iis. In IIS7 this is usually NETWORK SERVICE. So if you are using integrated security, you need to grant this account access to the database. If your SQL server instance is running on another machine, say SQLSERVER01, and your web app is running on your machine, YOURMACHINE, then the NETWORK SERVICE account on your machine will be called YOURMACHINE$ as seen by SQLSERVER01.
I'm using an AspNetSqlMembershipProvider for my application.
On my development machine I recently deinstalled SQL Server 2005 Express and Management Studio Express so that I could install the full version of Management Studio. I chose not to install SQL Server 2005 because, well, I don't want to have unnecessary things running on my machine.
Now whenever my code attempts to do anything that relates to authentication I get an error of:
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)
So, what is the minimum amount of SQL Server I have to install in order for this to work?
You could get away without having any SQL Server instances installed, especially if all you're using it for is Membership, Roles and the default Profiles.
The default connection string often looks like this:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/>
</connectionStrings>
If you change your SQL connection string, to match the value of "connectionString" above, that will force ASP.NET to generate the standard ASP.NET database for you withing the "App_Data" folder of your site - the keep part is "AttachDBFilename" which tells it to open the mdf file directly rather than attach to a SQL instance.
However, you might have some difficulty connecting to that file with SQL Management Studio.
You'll probably have to change the connection string once you move the site off development and into production, to point to a full instance of SQL if you so wish, rather than stick with the file based version.
Alternatively, what I tend do is have SQL Server installed (Express or otherwise), but the services stopped unless I'm actually using them. Then I just start them up when I'm developing.
Also you can have the Express version of SQL Server installed on the same machine as theh the full version SQL Management Studio without any problems.