Web Site Administration Tool:Unable to connect to SQL Server database - asp.net-mvc-3

I am developing an ASP.NET MVC3 application using,
MS SQL Server Pro 2008
MS VS 2010 pro
Entity FrameWork as model class.
When i start ASP.NET Web Site Administration Tool by clicking ASP.NET Configuration from solution explorer, in Security tab it shows an error:
Unable to connect to SQL Server database.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config has a connection string as,
<connectionStrings>
<add name="LocalSqlServer" connectionString="data source=.\MSSQLSERVER;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
I opened the
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql.exe
and configure the database default named 'aspnetdb'. But situation is not being improved. So, would you please help me to solve it.
Thank you.

Have you tried the database server that Visual Studio attempts to use?
It should match the one specified in your web.config file.
To check to go: Tools -> Options -> Database Tools -> Design-time Validation Database.
You can then change the SQL Server instance which is used.

Related

SQL Server database connection

I have an ASP.net web application and a database created on another computer. Now I want to run this on my computer.
I have installed SQL Server Express edition and SQL Server Management Studio on my computer and I copied database file to my SQL directory and attached it successfully through SQL Server Management Studio. Applications current connection string looks like this.
<add name="ASPNETDB"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
What do I have to change in this to make it work? FYI I have already copied database to SQL Server Management Studio default installation directory and attached it through SQL Server Management Studio express. Also I connect to SQL Server Management Studio using this server name.
localhost\SQLExpress
If you've attached the database to your SQL Server Express instance, then you should be able to use this connection string from now on:
<add name="ASPNETDB"
connectionString="Server=.\SQLEXPRESS;Database=ASPNETDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
With this, you basically tell your application
what server (instance) to connect to (.\SQLEXPRESS)
what database to use on the server (ASPNETDB - or whatever name you gave it)
to use integrated security (e.g. use your Windows credentials) to log on to SQL Server
That's all you need - SQL Server will handle all the details of dealing with data and transaction log files and all those nitty gritty jobs for you.

Connect MVC 3 application to sql server 2008

I am newbie and confused how to do it.
I have built MVC 3 application in Visual Studio 2010 and published to the localhost and it's working fine.
Here, What I actually want is to use the Sql Server 2008 installed in my computer rather than database under the folder APP_DATA that I have created using visual studio.
I am new to the MVC and don't know about the database connection detailly. Following is the connection string of the web.config file:
<connectionStrings>
<add name="IVRControlPanelEntities" connectionString="metadata=res://*/Models.IVRControlPanelModel.csdl|res://*/Models.IVRControlPanelModel.ssdl|res://*/Models.IVRControlPanelModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\IVRControlPanelDB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
This is the connectionstring automatically added by the visual studio while adding the data entity model.
After published to localhost the database used by mvc 3 is under the APP_DATA folder of wwwroot folder.
What I need to change to connect to the Sql Server 2008 installed in my computer rather than database created on the Visual Studio.
One more thing, I could not import the database created by visual studio to the sql server 2008 which is in the form IVRControlPanelDB.mdf
You should use Database.SetInitializer<> method in Application_Start method in Global.asax
read this and this ,this article may help too.
You need to modify your connectionstring to add the address to your sql server. Example:
<connectionStrings>
<add name="ApplicationServices"
connectionString="Server=localhost;Database=myDatabase;User Id=myUser;Password=myPassword;"
providerName="System.Data.SqlClient" />
</connectionStrings>

Get MVC3 to use Oracle for user roles and memberships

I'm having problems getting my MVC3 front end to use an Oracle 11g database to hold the user memberships.
I've been following this simple tutorial but can't get it to work.
Some things I've done so far:
Downloaded and installed the Oracle Data Provider for .NET (ODAC 11.2
Release 4 (11.2.0.3.0) )
Run the InstallAllOracleASPNETProviders.sql against the database on
the development server.
Tested the connection via SQL developer (using the TNSNames file)
with no issues.
Unable to create a connection to the database under the Server
Explorer pane is Visual Studio 2010 which seems related.
Having checked the database I can see that the "ORA_ASPNET_" tables have been created OK.
I'd appreciate a steer on where I'm going wrong as this SHOULD be easy.
The problem appeared to be related to the connection string.
I had been using the TNS names file for the connection details but this wasn't being picked up.
I modified the connection string to include the server, port and service name as follows:
<connectionStrings>
<add name="OraAspNetConnectionString"
connectionString="Data Source=svr56:1521/TCO1103;Persist Security Info=True;User ID=Ora_Asp;Password=*****;"
providerName="Oracle.DataAccess.Client="/>
</connectionStrings>
The problem creating the connection is the Server Explorer also resolved itself once I used the same details in the Data source name box.
svr56:1521/TCO1103;Persist Security Info=True;User
ID=Ora_Asp;Password=*****;

ASP.NET MVC 3 - Automatically created MDF file

I created an ASP.NET MVC 3 project using the default template, when I ran it and created an account, it automatically created an MDF file in my App_Data directory.
The problem is my development machine had a community preview of SQL Server 'Denali' installed, and the application needs to run on SQL Server 2008 R2 - so I can't attach the MDF file to the production instance.
I've changed the MDF file to be a SQL Server 2008 R2 database, attached it to a local instance, and added this to my web.config file (no connection strings were present before this):
<add name="ApplicationServices" connectionString="Data Source=127.0.0.1;Initial Catalog=MyDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
But my application still seems to look for the older instance, when I try to login now, I get this error:
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)
My question is - when Visual Studio 2010 automatically creates an MDF file for you, is there a connection string specified somewhere other than the web.config file?
I've searched through the code and can't seem to find one. I've verified I can connect to the SQL Server 2008 R2 database from other applications.
Any suggestions are welcome.
This was an issue in my Web.config file. It's fixed now.

Getting a ASP .NET MVC database working on a non-development machine?

This may be a basic question but I'm not very proficient in SQL Server.
I am Using Visual Studio 2008 Professional.
In a ASP .NET MVC 3 project I created a database that resides in 'App_Data'.
The web.config file uses this as the connectionString (partial):
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
When I copy the project to a the production server the initial MVC logon page appears ok. When I entire in the login username/password I get a
Failed to generate a user instance of
SQL Server due to a failure in
starting the process for the user
instance
error message.
The SQL Server Express 2008 instance on the production system is set use 'Local System' for authentication.
I think that I'm not configuring SQL Express or my web.config correctly?
UPDATE1
Most of the links found on the internet talk about deleting a folder. In my scenario there is no 'C:\Documents and Settings\YOUR_USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS' folder.
My solution for now (after much ASP .NET/IIS/SQL SErver security review) was to set "User Instance=True" to "User Instance=False" in the production web.config file.
Per your connection string, you're using Windows security to control access to the database. Does the account under which your web server runs have sufficient permissions on your database?
You may wish to test using SQL Server security, just to confirm this is the problem. (Assuming SQL Server was installed with SQL Sercurity enabled.)
Did you try this already? Fix error "Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance."

Resources