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