3

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...

0

2 Answers 2

3

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?

Sign up to request clarification or add additional context in comments.

10 Comments

I'll try that. I run everything on my machine (Win 7).
Your connection string works for the application DB, but when I want to use the web site administration tool I get the following error: Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.
I had that error before and I found some solutions (link), but they all didn't work for me. I tried to run aspnet_regsql.exe, but it failed and had exceptions.
I am confused with what you were trying to achieve then. I thought you wanted to use .mdf file to store user data. If this is not the case, then my connection string is wrong and the one given Win is correct. However, you first need to create that database using aspnet_regsql.exe. What exception do you get when you run it?
I've added that exception and more details to my question. But I've done some more research and I'll add that too under "edit 2".
|
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.