I have a CodeFirst web application that originally used LocalDb. I changed the connection string to:
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=.\SqlExpress;Initial Catalog=aspnet-BatchFindings;Integrated Security=True" />
And I created the appropriate database using Server explorer.
I am using WebDeploy to publish to a Windows Server 2012 instance running IIS8.
After publishing, I was unable to use the application; it did not have permissions for the database. I then changed the identity to a user account, and now I do not get database errors. Except the application does not appear to save any data to the database. I am at a complete loss - any help is appreciated!
Recap:
Entity Framework, Code First
Web Deploy to IIS 8
Custom Application Pool, identity set to a user account
Data not being stored in database.
EDIT: I would love to be able to simply use Web Deploy and have it use its own database (so it does not get test data from mine) but this is just so frustrating! I am publishing, the connection string should work, not sure where I am going wrong.
Stupid question but are you calling DbContext SaveChanges() method after data manipulation - data saving works when testing?
Also you can use different web.config files when testing (Debug) and deploying (Release version).
So I inadvertently figured out the reason why it was not saving. For some reason in my test environment everything worked, but when it was pushed out, I needed to add the following line:
db.Entry(obj).State = System.Data.EntityState.Added;
I checked out the tutorial, which seemed to work until it went into that Grant.sql file. There is no option in Visual Studio to connect.
What I ended up doing in that case to get the database working was set my Application Pool to run under a user identity I created for this purpose, while setting Load User Profile to True. You can also run as LocalSystem (as long as you create the following folder: C:\Windows\SysWOW64\config\systemprofile\Desktop - this tricks the system into thinking the LocalSystem account is interactive).
Related
Please help me a bit...
I have a domain with a web page, coded and compiled in VS2013, works like a charm... Then I decided to add a database, so I wrote one (ms sql). However, later when I deployed the project I can only watch the _Layout.cshtml file online, local everything looks perfect. What might be the problem? I've tried re-order some settings and scripts, but without success. A supplementary question, can the Connectionstring cause this? I've been having some problems with that nasty row.
This is my connectionstring for deploy:
<add name="20066_name" connectionString="Data Source=name-20066.mssql.domainaddress.com;Initial Catalog=20066-name;Integrated Security Info=True;User Id=secret;Password=secret" providerName="System.Data.SqlClient" />
So locally works fine with a local database, or using the connection string's remote database?
Try using the remote connection string with the local deployment and see if it connects. If it does, then you need to check the properties on the publish dialog. There is an option for altering the connection strings when you deploy (you might have heard this process as web.config transformation), so make sure that you send the correct connection string to the remote web server.
The connection string seems ok. You can experiment with more options though. Check the following link for ideas http://www.connectionstrings.com/sql-server/
I finally have a published website. Now I want to continue development so I changed my webconfig back to the previous working localdb connection string.
<add name="HouseContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MVCBSV;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MVCBSV.mdf" providerName="System.Data.SqlClient"/>
and then commented out the connection string to the production server.
<!--<add name="HouseContext" connectionString="Data Source=bstatus2014.db.10188888.hostedresource.com; Initial Catalog=bstatus2014; User ID=bstatus2014; Password=Bstatus!2014;" providerName="System.Data.SqlClient" />-->
But when I run the project, the data that is retrieved is the production data! I've tried clean and then build solution but no effect. Probably related, is that I published to the local IIS following the web deploy suggestions adding an application pool. Also if I use the connection wizard specifying localdb/v11.0 it no longer shows my MVCBSV.mdf db.
Also I was trying to use transforms debug/release to make this change, but have found a post that transforms don't work on debug.
A beginner so explicit answers are a help.
Yea, if you publish to your local IIS then your application is probably tied to that site. Open IIS, find the published site open the folder your published code is in and then look at the Web config it is associated to it. Also try recycling the app pool.
Transforms should only be used when you are publishing to a non-local environment anyway. Beyond that if you publish it might make more sense if you published to a location in your file system.
I followed the "Creating an Entity Framework Data Model for an ASP.NET MVC Application" in ASP.net and changed it to meet my needs.
I built the project and run it - everything works fine (I can view details, edit and save).
I press "Show all files" and there is nothing under App_Data.
I tried to read the related threads here but i couldn't fix it.
I will appriciate any Idea!
this is my connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
Thank you!
First thing is that your connection string indicates this is a SQLExpress database file. Probably located under the data directory under SQLExpress install location.
Second, I ran a tutorial and chose to use a SQL Compact database. That file (.sdf) I would expect to show up under the App_data folder. It did not. Since the database was generated via 'code first' I suspect this is a bug. All I had to do to fix it (working in the Solution Explorer of VS 2012 RC) was right-click on the App_data folder and choose . And I had to set the .sdf file properties so it would copy to the output file.
I knew I had to do this because my web deploy failed to write the .sdf file to my IIS server. When I republished, the 'Preview' showed me that the .sdf file was going to deployed to /bin/app_data of my web application folder.
If you are using a SQLExpress database, it might require slightly different steps. But your problem is similar and I think we can say this is a bug in the Entity Framework when working within Visual Studio.
To all of those who "tried everything" when it comes to this issue and it still doesn't work, if you can run the app, try saving a record in the database, as the .sdf file will only be created once the first record is created. Then switch off and on again the show all files button and the .sdf file should show up.
Good luck!
I'll start with appologies; I wasn't sure if this was best posted here of Server Fault so if its in the wrong place then please move :-)
Basic information
I have written the first module of a new application at work. This is written using Visual Studio 2010, targetting .net 3.5 (at the moment) and asp.net mvc 2. This has been working fine during development running on the built in Development server from VS but however does not work once deployed to IIS 7/7.5.
To deploy the application, I have built it in release mode and created a deployment package by right clicking on the project in the solution explorer (this will be done with an automated build in tfs once upgrade from the beta). This has then been imported into IIS on the server.
The application is using windows/domain authentication.
Issue #1
I can fire up internet explorer and browse to the application from a client computer as well as on a remote desktop connection. I can execute the code which reads/stores data in Session fine from the IE instance on the remote desktop but if I browse to it from the client pc it seems to lose the session state. I click on the form submit and the page refreshes and doesn't execute the required code. I've tried setting with; InProc, SQLServer and StateServer. but with no luck :-(
Issue #2
As part of the application it views PDF and Tiff documents on the fly which are on a network share on the office network and creates thumbnails if the document hasn't been viewed before. This works if running on the machine the application is deployed to; however when browsing from a client pc I get an error saying:
Access to the path '\\fileserver\folder\file.tif' is denied
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.UnauthorizedAccessException: Access to the path '\\fileserver\folder\file.TIF' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
As this is on a different server the user is not accessible. To get round this I have tried:
1 - setting the application pool to run as domain administrator (I know this is a security risk, but I'm just trying to get it to work at the moment!)
2 - to set the log on account for World Wide Web Publishing service to be the domain admin . When trying to restart the service I get ...
Windows could not start the World Wide Web Publishing Service service on the Local Computer.
Error 1079: The account specified for this service is different from the account specified fro the other services running in the same process.
Any pointers/help would be much appriciated as I'm pulling my hair out (of what little I have left).
Update
I've been using this funky little tool I found -
DelegConfig v2 beta (Delegation / Kerberos Configuration Tool). This has been really usefull. So I've got the accessing of the file share working (there is a test page which will read the files) so now I've just got the issue of passing through the users credentials through to the SQL Server (wans't my choice to do it this way!!) to execute the queries etc. but I can't get it to log on as the user. It tries to access it as "NT Authority\Network Service" which doesn't have a sql login (as should be the logged on user).
My connection string is:
<add name="User" connectionString="Data Source=.;Integrated Security=True" providerName="System.Data.SqlClient" />
No initial catalog is specified as the system is over multiple dbs (also wasn't my choice!!).
I really appriciate all the help so far! :-)
Any further hints?!
Issue #2 - Your options are:
Configure delegation (double-hop authentication) - I haven't done this on IIS7 and it's a bit different to 6, but I believe you will need to enable the web server machine account for delegation in AD, and create an SPN for the web server (eg setspn -A http/<Web Server FQDN> <Domain>\<Machine Name>). Troubleshooting Kerberos can be fairly painful.
Grant access to the network resources to the (domain) application pool account and make sure anonymous authentication is turned on ( <anonymousAuthentication enabled="true" userName="" defaultLogonDomain="" /> )
Response to Update:
You will need to make sure Kerberos authentication is working for SQL Server. Run the query select auth_scheme from sys.dm_exec_connections where session_id=##spid; it will return NTLM or KERBEROS. If it's NTLM, you'll need to do some work configuring SQL Server to use Kerberos. Set an SPN in AD for the SQL service account: setspn -A MSSQLSvc/<SQL Server FQDN>:1433 <Domain>\<Sql Service Account>, restart SQL Server and try the query again. You must use TCP/IP as the connection mechanism (this is the default).
If you don't have an initial catalog, you'll need to make sure that all of the user logins have a default database that they have access to. I would personally pick one database to be the initial catalog as you may get different behaviour depending on how the login is configured.
With this small part of information I could only give some hints:
Issue #1:
Maybe you have a misleading URL as action for the form? Or an caught&ignored exception? Do you have an onError-event in your global.asax.vb?
Sub Application_Error()
Dim ex As Exception = Server.GetLastError
' NOW HANDLE THE EXCEPTION --> REPORTING :-)
End Sub
Issue #2:
I recently had the same exception - I had to check the access-rights for users for this folder and set the appPool-identity to "NETWORKSERVICE". In your case you even try to access a network-folder - check the accessrights on the server and try to use the IP instead of the name - it could be a name-resolution-problem?!
Sorry for this small portion of information... This looks like problems only solveable with direct debug-options on the running server.
Finally last thing on Friday I got it working ...
As I said in the update, the tool for sorting out the delegation of credentials was very handy and helped no end to setting the correct SPN records.
I found I also had to set it up for SQL as I was passing through the credentials into the server. The other thing I found stopping the connections was some of the inbound windows firewall settings where causing problems.
For the connection string; I had to update to:
<add name="ConnectionStringName" connectionString="Data Source=.;Integrated Security=SSPI;Trusted_Connection=True" providerName="System.Data.SqlClient" />
Links I found useful:
Kerberos Authentication and SQL Server
DelegConfig
And even tho it mainly talks about Sharepoint ... this was also useful.
Hope this helps people in the future.
I'm just starting with ASP.NET MVC and I was trying the Authentication with this new architecture.
So, I started following a tutorial in the official site and, while I was trying to add some users through the Web Site Administration Tool, I found this error:
There is a problem with your selected data store. This can be caused by
an invalid server name or credentials, or by insufficient permission.
It can also be caused by the role manager feature not being enabled.
Click the button below to be redirected to a page where you can choose
a new data store.
The following message may help in diagnosing the problem: Could not load type
'MyMvcApp.MvcApplication'.
Now, the only thing I changed in the web.config was the connection string and, I'm sure the connection string is not the problem (is the same I'm using in other project).
EDIT: Here is the connection string: "Data Source=myMachine\SqlExpress;Initial Catalog=TestDB;User ID=TestUser;Password=123456"
I tried several things and googled a lot, but nothing worked.
So, any ideas? as I said, I did not change anything in the web.config besides the connection string.
Thanks in advance,
Found the problem: I just need to COMPILE the solution BEFORE starting the WSAT.
Thanks to everyone for your answers.
Well, like the message says, this feature requires real management enabled, and the default MVC web site template has this disabled. Go into Web.config and change:
<roleManager enabled="false">
to
<roleManager enabled="true">
One other thing to check: Make sure that when you create the SQL Membership Provider metadata you connect as a user who will be useful at runtime. In other words, if you connect as sa, then the metadata will be in the dbo schema. But if you connect as yourself, then the metadata will be in your schema, which isn't necessarily useful to other applications. You should run SQL Server Management Studio in order to verify in which schema the metadata is placed.