ASP.net: Cannot use Website Administration Tool because of database error - asp.net

This is my first project using ASP.net and I'm struggling to get my database connection working.
Right now the database for my application data is working and I can use the website to do simple CRUD operations.
However, when I try to add Authorizarion and Authentication via the Web Site Administration Tool I get the following exception:
Cannot open user default database. Login failed. Login failed for user 'PcName\UserName'.
I have tried solving this problem by using different connection strings, but without luck. They would just break my website functionality.
My connection string is:
<connectionStrings>
<add name="ProjectEntities"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
database=ProjectDB;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I'm using Visual Studio 2010, with ASP.net MVC 3 and the Entity Framework.
I'm really out of options here, there is way too much information about SQL Server Express and ASP.net and I just can't find any working solution.
EDIT:
I tried several different connection strings as suggested below and found online. I now have a different error when trying to load the Web Site Administration Tool: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
When Googling that I found some solutions to fix that problem. One of those was to run aspnet_regsql.exe with some option. When doing that I get the following error message:
An error has occurred. Details of the exception:
A network-related or instance-specific error occurred while establishing a conne
ction 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: Named Pipes Provider, error: 40 - Could not open a conne
ction to SQL Server)
Unable to connect to SQL Server database.
Somehow it seems that the SQL server is not running, or something. My knowledge about this subject is really insufficient to fix this problem.
EDIT 2:
I've done some more research and just tried to run the Web Site Administration Tool of an newly created MVC 3 Internet Application. When going to the security tab it gives me a different error: Could not load type 'MvcApplication1.MvcApplication'.
So my guess is that I'm missing some configurations in Web.config in my initial project (created as empty project), but somehow there is a new problem...

Can you try without specifying database parameter?
<connectionStrings>
<add name="ProjectEntities"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
AttachDBFilename=|DataDirectory|aspnetdb.mdf;
User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Does it creates the .mdf file at all? Are you working on network drive?

the connection string should be:
<connectionStrings>
<add name="ApplicationServices" connectionString="data Source=.\SQLEXPRESS; Initial Catalog=aspnetdb; Persist Security Info=True; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

Related

ASP.NET Identity always shows error "CREATE DATABASE permission denied in database 'master'."

I created an ASP.NET MVC5 project with default template and individual user account authentication (identity).
I changed default connection string to connect my existing database that includes all tables necessary for identity.
Here is my connection string:
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;User ID=sa;Password=123456;"
providerName="System.Data.SqlClient" />
Everything works fine locally, but when I login identity in hosting, I get this error:
CREATE DATABASE permission denied in database 'master'.
Then I tried again with a new project without identity, I add an ADO.NET Entity Data Model connect to my existing database from my project and get some data to show in a view. It works fine locally and in my hosting environment.
Can someone please explain and help to fix error in case 1? Sorry my English is not good, thanks you so much.

Setting up ASP.NET in Plesk Web Host Edition

So I'm in the process of making the configurations for my site on Plesk Web Host Edition but unfortunately I have an issue of accessing the database through my website.
I have noted the following:
1. I can access the Database through SQL Server Management Studio (SSMS) without any issues but one important thing to mention is that when I try to make my DB user as the owner of the database I get the following error:
Cannot alter the role 'db_owner', because it does not exist or you do not have permission. In other words, I'm not the owner of the database and I can't alter anything in it! although that I have created the database and the DB user through Plesk Panel.
2. I configured the web.config as follows:
<add name="xxxConnectionString" connectionString="data source=127.0.0.1\SQLEXPRESS;server=127.0.0.1;database=xxxx.mdf;Uid=xxx;pwd=xxxx" />
3. When accessing the website I get the following error:
Cannot open database "xxx.mdf" requested by the login. The login failed.
Login failed for user 'xxx'
I contacted the support of the hosting provider but it's been almost 4 days now without any reply. I'm really hoping of finding the answer with you guys.
Thanks in advance
I was able to find a solution for the ConnectionString issue. Below is the connection that I used to fix the issue:
<add name="CarRentalConnectionString" connectionString="Data Source=localhost;Initial Catalog=DATABASENAME;Integrated Security=false;User ID=USERNAME;Password=PASSWORD" />

how to find the sql connection string in asp.net

I added a new Sql Server Database to my project with the name: ShDB.mdf. It is located in a App_Data folder.
It contains a Table which has some columns. I could add some numbers to the table and then show them in a gridview on my localhost.
This is what I have in the web.config:
`<configuration>
<connectionStrings>
<add name="ShConnectionStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Javad\Desktop\Sharj\App_Data\ShDB.mdf;Integrated Security=True;User Instance=True"/>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ShDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
</system.web>
`
Here is the vb.net code which I used:
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ShConnectionStr").ConnectionString
And it works properly on the localhost test but when I published the website and uploaded the files on a web hosting service to test, I counter an error. How may I fix it? I think I should change my Data source path but I don't know how because its my first experience. Thanks to any help. you can see the error page here: http://www.kaj.somee.com/SL.aspx
Sql Server is either not installed or not running on the web host, or you don't have access to connect to it.
ASP.Net does not by itself know how to use your *.mdf database. It needs a running instance of Sql Server to talk to. It will tell Sql Server to load (attach) your database file, and then send queries to the Sql Server service for execution.
Do you mean you already uploaded the website to a web hosting service, but not the database?
If so, your application may not communicate directly with your database which is actually in your local machine.
You probably need to upload the database to a database hosting service as well (eg.SQL Azure, etc).
You may need to figure out the IP address/Server Name of your database hosting where you have uploaded. These information you can probably get in for the service provider. From there you should be able to connect to the database with the correct configuration.

"The connection string specifies a local Sql Server Express instance", Except it Doesn't

I'm trying to deploy an asp.net application to a server using a SQL Server instance for the ApplicationServices membership database.
The problem is, I'm getting an error that says
The connection string specifies a local Sql Server Express instance
using a database location within the applications App_Data directory
I got this error when I initially tried to deploy the aspnetdb.mdf itself with the application.
I got this error when I then scrapped that plan and decided to do a web.config transform so that in Debug I use the Express database, but on Release the connection string goes to SQL Server.
I got this error again when I decided out of curiosity to remove all references to the express database from the code, so there could be no possible way anything would be looking for the Express database. No luck.
Does anyone have any ideas about this? I have deleted and re-installed the web site in IIS each time, noting that there is no App_Data being deployed and no mention of the .mdf file in web.config - to no avail. It still thinks there's a connection string telling it to look for a SQL Server Express database :/
Edit: Here's the connection string I'm using. Pretty standard, I think, but I could always be wrong.
Data source=HERP;Initial Catalog=DERP;Integrated Security=True
Could the error refer to the default connection string from the machine.config file (the LocalSqlServer one)? This could be happening, considering that the default membership provider uses this connection string:
The following default membership element is configured in the
Machine.config file [...]:
<membership>
<providers>
<add name="AspNetSqlMembershipProvider" [...]
connectionStringName="LocalSqlServer" [...]
Do not forget to clear the connectionStrings first:
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

ASP.NET Web Application Administration Security section: Unable to connect to SQL Server DB

I am using SQL Server Web (Full version not SQLExpress). I can connect to the database fine from my VS2010. However when I go to ASP.NET Web Application Administration, click "Security" I got below 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: Unable to connect to SQL Server database. "
I know I miss something. Can somebody help?
Thanks
Just a tip, have a look in your web.config file and set YOURMACHINENAME in the data source
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Integrated Security=SSPI;Data Source=YOURMACHINENAME ;Initial Catalog=aspnetdb;" providerName="System.Data.SqlClient" />
</connectionStrings>
Hope it help

Resources