MVC 3 - After publishing to server - CREATE DATABASE permission denied in database 'master' - sql-server-2008

Setup
MVC 3 EF 4.1 Code First - Windows 7 Pro 64 Dev machine, Separate Win 7 Pro for host.
I started with a SQLCE4.0 database, and everything worked fine (database initializer created tables, populated, etc...).
Once I got everything working like I wanted, I scripted out my SqlCe DB, created a real SQL 2008 DB, opened the proper ports and enabled TCP connections.
Problem
IF I Change my connection string to point to my intranet server\instance name, with a user I created for this app specifically, it works perfectly running from my dev machine.
IF I publish the app to the server (the web server and sql server are the same), and I try to login to the website (aka access the db), then I get:
CREATE DATABASE permission denied in database 'master'.
I commented out the DBInitializer setup so nothing should be created upon a db hit. The tables are there already.
If I do Database.SetInitializer(null); then I get a different login error:
I don't remember exactly but it was something to the affect of LOGIN FAILED FOR IIS APPPOOL\ApplicationPoolIdentity
So I changed the Identity to NETWORK SERVICE and even tried LOCAL SERVICE, both giving the same login failed error.
I tried following this post who says add a SQL user named 'IIS APPPOOL\MyApplicationName'. SQL Wont let me do that as it has invalid characters ... go figure.
Why does it work perfectly over the network accessing the DB from my dev machine, but when I publish to THE SAME machine that hosts the sql and the site, I get permission denied or login failed errors? I've scoured the net and tried different things.
EDIT: Here are my connection strings:
<add name="AntripContext" connectionString="Data Source=|DataDirectory|AntripWeb.sdf" providerName="System.Data.SqlServerCe.4.0" />
<!--<add name="AntripSQL" connectionString="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;" providerName="System.Data.SqlClient" />-->
<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\AntripWeb.sdf"" providerName="System.Data.EntityClient" />
<!--<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;"" providerName="System.Data.EntityClient" />-->
Note: The commented out connection strings are the ones that use the sql 2008 database (that break my published app).

It sounds to me as if your connection string has Integrated Security=true so that you are connecting to SQL as the user you specify, rather than the SQL user you think you are using?
But beware, its still trying to create a database: you need to swap the IDatabaseInitializer - I guess it will look for a DB named the same as the entitys to be careful!

Related

Sql login failed in dotnetnuke(dnn)

I am trying to install dotnetnuke in my localhost but not able to installing dnn and below connection string used in webconfig file.
<add name="SiteSqlServer" connectionString="Server=(local);Database=d1;uid=;pwd=;" providerName="System.Data.SqlClient" />
Below error getting:
I am installing dnn in local host, please help to out this headache installation.
Integrated will attempted to use Windows Authentication for the database connection.
You either need to create a SQL authentication account and choose the "User Defined" option, or you need to add the user for your app pool to SQL to give it access to the D1 database.
I prefer to just use SQL Auth accounts, always ends up easier in my opinion.

MySQL ASP.net Connection string error

I'm trying to connect to MySQL from my asp.net website on a hosted platform. My connection string looks fine, all the login details and server IP are correct but I am still getting an error on the page:
[Win32Exception (0x80004005): The network path was not found]
provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server
web.config connection string:
<connectionStrings>
<add name="Conn" connectionString="Server=xxxx;Database=xxxx;Uid=xxxx;Pwd=xxxx;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
Can you guys give me any more info why this might be the case? Thanks!
Your server is not running or if running, your code cannot access this - firewall, etc. Or you didn't granted privileges for the IP of your app.
Looks like on this occasion there was a random Import that was making my site think it was using MSSQL rather than MySQL. Removed this and it's now working. Thanks for the help!

Ef code first migrations on server:Cannot open database "blahblah" request by the login. The login failed

There are a million threads like this but none where the answers worked.I'm trying to get this database set up on my server (which I can remote into), but every time I try and run the web app I get this error. Why is code first not creating the database? Here's some relevant code.
Connection string in web.config
<add name="Context" connectionString="Data Source=Server\Instance;Initial Catalog=myDb;Trusted_Connection=false;User Id=User;Password=password;" providerName="System.Data.SqlClient" />
Global.asax relevant portion
Context context = new Context();
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());
context.Database.Initialize(true);
if (!WebMatrix.WebData.WebSecurity.Initialized)
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection("BaseContext",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
you're using integrated Windows authentication, you need to create a SQL Server login for "yourUser\ASPNET" on your SQL Server - or change your connection string to something like :
<add name="Context" connectionString="Data Source=Server\Instance;Database=myDb;Id=User;pwd=password;" providerName="System.Data.SqlClient" />
The login failed error is inside sql server error. Try if you have SQL Managment Studio logged using your data in connection string - Context.
I only thinking, but when you migrating your database recreate your user sql account and rester sql server.
Or
Try create new user by SQL Managment studio and then try usgin this data to connection string.
Check when you create user account, is not checked user must changed password first time.
I think my idea resolved your problem :)

SQL Server 2008 Connection Error "No process is on the other end of the pipe"

Let me begin by saying, I am aware of this thread and others around the web that seek to trouble shoot this issue.
The solutions posted there do not apply to my issue. I have spent 5 hours trying to resolve this before deciding to ask the question.
The problem:
When I attempt to log into SSMS (or connect from a java application) using SQL Authentication I get this error:
A connection was successfully established with the server, but then an
error occurred during the login process. (provider: Shared Memory
Provider, error: 0 - No process is on the other end of the pipe.)
(Microsoft SQL Server, Error: 233)
Although it does work, it is not an option for me to use integreated authentication.
The database I am attempting to connect to is on the same machine as my SSMS instance. There is no network, this is a stand-alone system.
NAMED PIPES is ENABLED in my configuration, I HAVE rebooted since, TCP IP is a higher priority than named pipes in my configuration.
I have even gone as far as to uninstall SQL Server and reinstall it, to no avail.
The details of my SQL Server instance are as follows:
Microsoft SQL Server Management Studio - 10.0.2531.0
Microsoft Analysis Services Client Tools - 10.0.1600.22
Microsoft Data Access Components (MDAC) - 6.1.7601.17514
Microsoft MSXML - 3.0 5.0 6.0
Microsoft Internet Explorer - 9.0.8112.16421
Microsoft .NET Framework - 2.0.50727.5466
Operating System - 6.1.7601
Configuration details are as follows:
http://i45.tinypic.com/vxdz7c.png
http://i45.tinypic.com/vxdz7c.jpg
I connect from java using this code.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost;database=AdventureWorks;integratedSecurity=false;User=JIMBO; Password=JIMBO;";
Connection con = DriverManager.getConnection(connectionUrl);
But please remember, this error also occurs when I atttempt to log in to SSMS directly.
Thanks in advance.
-Jim
To force TCP/IP being used replace localhost with 127.0.0.1 in your connection string.
As you are using a username and password make sure SQL authentication is enabled. By default only Windows integrated is enabled on sqlserver 2008.
With SqlServer authentication keep in mind that a password policy is in place to enforce security.
Forcing the TCP/IP connection (by providing 127.0.0.1 instead of localhost or .) can reveal the real reason for the error. In my case, the database name specified in connection string was incorrect.
So, here is the checklist so far:
Make sure Named Pipe is enabled in configuration manager (don't forget to restart the server).
Make sure SQL Server Authentication (or Mixed Mode) is enabled.
Make sure your user name and password are correct.
Make sure the database you are connecting to exists.
My resolution was to login using the Windows Login then go to security>Logins locate the troubled ID And retype the used password. The restart the services...
Adding "user instance=False" to connection string solved the problem for me.
<connectionStrings>
<add name="NorthwindEntities" connectionString="metadata=res://*/Models.Northwind.csdl|res://*/Models.Northwind.ssdl|res://*/Models.Northwind.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS2008R2;attachdbfilename=|DataDirectory|\Northwind.mdf;integrated security=True;user instance=False;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
This problem was caused for me by this error which appeared just prior in the application error log.
"A read operation on a large object failed while sending data to the client. A common cause for this is if the application is running in READ UNCOMMITTED isolation level. This connection will be terminated."
I was storing PDFs in a SQL table and when attempting to SELECT from that table it spit out that error, which resulted in the error mentioned in your question.
The solution was to delete the columns that had large amounts of text, in my case Base64 encoded files.
perhaps this comes too late, but still it could be nice to "document it" for others out there.
I received the same error after experimenting and testing with Remote Desktop Services on a MS Server 2012 with MS SQL Server 2012.
During the Remote Desktop Services install one is asked to create a (local) certificate, and so I did. After finishing the test/experiments I removed the Remote Desktop Services. That's when this error appeared (I cannot say whether the error occured during the test with RDS, I don't remember if I used/tried the SQL Connection during the RDS test).
I am not sure how to solve this since the default certificate does not work for me, but the "RDS" certificate does.
BTW, the certificates are found in App: "SQL Server Configuration Manager" -> "SQL Server Network Configuration" -> Right click: "Protocols for " -> Select "Properties" -> Tab "Certificate"
My default SQL Certificate is named: ConfigMgr SQL Server Identification Certificate, has expiration date: 2114-06-09.
Hope this can give a hint to others.
/Kim
For me it was because only Windows Authentication was enabled. To change security authentication mode. In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
Change Server Authentication Mode - MSDN - Microsoft
https://msdn.microsoft.com/en-AU/library/ms188670.aspx
This Might help as reference
I had the same issue, after multiple trial of suggested solution on this site and others, I found a solution for my scenario. The account was locked out
How to Check if the account is Locked out...
Login to the server using higher privileged account (like SA or admin rights)
Expand security ==> select the login name ==>open the property window of the login ==> select the status page on the property window
Make sure This 3 Things
1, permission to connect database is GRANTED
2, Login is ENABLED
3, Status
SQL server authentication
Login is not locked out (Uncheck the box)
Thanks
Tsige
I just executed connection.close() by adding it as first statement and it was solved. Then i removed the line.
One follow up to this. I had installed SQL Server 2014 with only Windows Authentication. After enabling Mixed Mode, I couldn't log in with a SQL user and got the same error message as the original poster. I verified that named pipes were enabled but still couldn't log in after several restarts. Using 127.0.0.1 instead of the hostname allowed me to log in, but interestingly, required a password reset prompt on first login:
Once I reset the password the account worked. What's odd, is I specifically disabled password policy and expiration.
Another cause is if the user's default database is unavailable.
I had an account that was used for backing up two databases. When the backup user's default database was taken off-line, the "no process on the other end of the pipe" error started.
Came here looking for a solution to a similar issue, which I just introduced by changing Schannel settings of our IIS server using "IIS Crypto" by Nartac... By disabling the SHA-1 hash, the local SQL Server was not able to be reached anymore, even though I didn't use an encrypted connection (not useful for an ASP.Net site accessing a local SQL Express instance using shared memory).
Thanks Count Zero for pointing me in the right direction :-)
So, lesson learned: do not disable SHA-1 on your IIS server if you have a local SQL Server instance.
For me the issue seems to have been caused by power failure. Restarting the server computer solved it.

use of universal providers and mysql

I created an asp.net mvc 4 application, and added universal providers, because I need to create a custom membership provider that read users data from a my sql database.
When I work on the developer workstation it's all ok, but when I deploy on the server, where there is not Sql Server installed i receive an error. trying to open DefaultConnection.
In the InitializeSimpleMembershipAttribute that is created from the wizard, I have this:
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: false);
this call initialize the db connection, do nothing, and is not used by the custom membership provider, but must be done at startup.
the connection string is:
add name="DefaultConnection" connectionString="Data Source=...;Initial Catalog=...;User id=...;Password=..." providerName="System.Data.SqlClient" />
the problem is that I don't know how to configure to use a mysql db and pass this control in the startup of the application.
If I have to install it in a server with Sql server installed, I configure it properly, and after the initial call the mysql membership provider works without problem, but i have problems when i cannot use this workaround, and exception is raised at the call to InitializeDatabaseConnection.
How can I fix this problem?