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.
Related
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.
I have an MVC 3 app using Entity Framework that was happily hosted in Azure and talking to SQL Azure Database 2 days ago. I then had a minor schema change to the database and so dropped and re-created the database via SSMS and also published the application again as I had added the default MVC app login role controls to the site - since then I cannot get my app to connect to the database and get the following error logged in an Elmah xml file:
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)" source=".Net SqlClient Data Provider" detail="System.Data.EntityException
I can connect to the SQL Azure Database using SSMS and when I run my application in the Azure emulator connected to the SQL Azure Database everything runs perfectly but once published it refuses to connect. Any help would be massively appreciated!
A SQL Azure connection string (using EF Model First / Database First) typically lookes like this:
<connectionStrings>
<add name="SampleEntities" connectionString="metadata=res://*/Models.SampleEntities.csdl|res://*/Models.SampleEntities.ssdl|res://*/Models.SampleEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:abcdefg.database.windows.net,1433;Database=asdf;User ID=manager#abcdefg;Password=XXXXXX;Trusted_Connection=False;MultipleActiveResultSets=True;Encrypt=True;"" providerName="System.Data.EntityClient" />
</connectionStrings>
A SQL Azure Connection string (using Code First) typically looks like this:
<connectionStrings>
<add name="SampleContext" connectionString="Data Source=tcp:abcdefg.database.windows.net,1433;Database=asdf;User ID=manager#abcdefg;Password=XXXXXX;Trusted_Connection=False;MultipleActiveResultSets=True;Encrypt=True" providerName="System.Data.SqlClient" />
</connectionStrings>
The second connection string will also work without Entity Framework.
I believe you've published a config to Azure that does not have a correct SQL Azure server name, but rather some local/on-premise SQL server. Could this be it? Can you remote into the instance and validate correct .config and SQL Azure server?
From the error it appears that your app is not using TCP/IP to connect to your SQL Azure, but rather Named Pipes, which usually implies that the SQL Azure server name is not likely a valid TCP/IP host.
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=*****;
I just published my mvc3 application that uses the default membership provider to login but it seems that the call to anything "Membership" (Membership.ValidateUser-in this case) is causing the following error on the remote server hosting my web application.
Server is 2003 SP2 IIS6.0...my mvc3 application hits sql server 2008 instance.
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)
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.
SQLExpress database file auto-creation error:
How is the out of the out of the box (new mvc3 app) user/login managed with MVC3 and how can I set this user store up on my remote IIS server?
By default it creates a connection to a local SQL Express db in your App_Data folder the first time you run the mvc web app and register a user. You will then notice the aspnetdb file is created.
If you wish to use your existing db you need to create the Membership schema on an existing database.
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Easiest way is to update the web.config connection string to point to new db and run the install scripts agaist this.
These scripts are located in the WINDIR%\Microsoft.Net\Framework\v2.0.50727\ folder with names like InstallCommon.sql, InstallMembership.sql, InstallRoles.sql, InstallProfile.sql, InstallSqlState.sql, and so on.
See this more in depth article for full overview
http://www.asp.net/security/tutorials/creating-the-membership-schema-in-sql-server-cs
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."