Groups | Blog | Home
all groups > visual studio .net setup > august 2006 >

visual studio .net setup : Could not establish a connection to the database


bruno
8/22/2006 11:24:02 AM
I've Visual Studio 8 and SQL Server 2005 installed on my computer. I'm quite
new on Visual Studio and getting experienced on ASP.NET programming.
I'm finding problems in experimenting Authentication and Roles solutions
because ASP.NET configuration tool gives me this error message:

"Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site
Administration tool, use the aspnet_regsql command-line utility to create and
configure the database, and then return to this tool to set the provider."

I've just run aspnet_regsql and checked the presence of the aspnet database.
I have to instances of SQL Server:
My_PC_Name\Pinnacle
My_PC_Name\SQLEXPRESS (where the aspnet database has been created)

Can you give me any help? Hope this is the rigth site to post my problem.
Many thanks.

--
stcheng NO[at]SPAM online.microsoft.com
8/23/2006 12:00:00 AM
Hello Bruno,

From your description, after you installed Visual Studio 2005 and SQL
Server 2005 on the machine, when creating a new ASP.NET application and use
the web admin tool to configure the ASP.NET application, you're getting the
following error, correct?

<<<<<<<<<<<<<
"Could not establish a connection to the database.
...............
[quoted text, click to view]


Based on my experience, the problem could be caused by the following things:

1. The admin tool/ASP.NET runtime try connecting to a non-existing database
instance(according to the configured provider, membership or role manager
...)

2. The target database instance does exsits, but the current
application/'security context can not establish connection to it.

For your scenario, I noticed that you've mentioned the following installed
instances on your machine:

**My_PC_Name\Pinnacle(is this the SQL server 2005 server instance?)
**My_PC_Name\SQLEXPRESS(surely this is the SQLEXPRESS instance installed
with VS 2005)


If the above is the case, I'd like to confirm the following things with you:

1) Have you done any changes in the machine.config or your ASP.NET
application's web.config to customize any of the ASP.NET service
providers(such as membership, rolemanager ....)? Also, when using the web
admin tool, it is on which page and performing which operation did you get
the error?


2) by default in the machine.config, it contains the following default
connectionstring for all the SQL Server providers:

<connectionStrings>
<add name="LocalSqlServer" connectionString="data
source=.\SQLEXPRESS;Integrated
Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User
Instance=true" providerName="System.Data.SqlClient" />

You can check whether this is the value on your machine. And if you're
trying to use the default SQL server provider, it will use this
connectionstring to establish connection to the sqlserver instance. (if
success, it will create a aspnetdb.mdf file in your application's App_Data
sub directory).


3) If you're trying to connect to custom SQL Server database instance
instead of the default SQL express one, what custom configuration have
performed on the machine? Make sure the SQL Server instance and SQL Express
instance has been started.



In addition, for general testing, you can try the following things:

i) try creating a normal sql express mdf file in your web application's
"App_Data" folder by "Add New Item---> SQL Database" menu to see whether
you can explicitly create a sqlexpress database file

ii) are you developing the web application in VS 2005 through file sytsem
project or IIS host project? You can try both mode to see whether it
behaves differently.

iii) Here is a web article introducing how to use non-default(SQL Express)
database for ASP.NET providers, if your problem is related SQL Express, you
can use its guide to create custom provider setting against your SQL Server
2005 server instance to see whether it works.


#ASP.NET 2.0 App Service Config Issues When Not Installing Sql 2005 Express
http://aspadvice.com/blogs/plitwin/archive/2005/11/04/13590.aspx

Hope this helps. If there is anything unclear or any other information you
wonder, please feel free to let me know.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.


bruno
8/23/2006 12:43:02 PM
Hello Steven,

actually I solved the problem applying one of the two solutions given in the
document you suggested -->
http://aspadvice.com/blogs/plitwin/archive/2005/11/04/13590.aspx.
I changed the web.config, with a remove and add name="LocalSqlServer".
Now it works, I can access Security tab in ASP.NET Web Site Administration
Tool. But in the web.config I had to specify: connectionString="Data
Source=localhost\SqlExpress ... instead of connectionString="Data
Source=localhost, as reported in the Paul Litwin's Blog (??).

About the two points you would to confirm:
1) No changes have been done in machine.config neither in ASP.NET
application's web.config
2) My machine.config contains the connection string exactly as you
mentioned, but not able to crate any *.mdf file
3) SQL Server (SQLEXPRESS) is a running service, the executable file path
is: "C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Binn\SQLAGENT90.EXE"
-i SQLEXPRESS

general testing:
[quoted text, click to view]
I got a message box saying:
"Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to
function properly. Please verify the installation of the component or
download from the url: http://go.microsoft.com/fwlink/?LinkID=49251.

Know I can proceed with my tests and learning, but I would like to be able
to create also ".mdf" files. So do you think I should re-install SQLExpress
2005 or VS2005?

Thank you
--
bruno


[quoted text, click to view]
bruno
8/23/2006 12:48:02 PM
Sorry, this is the path of the SQL Server (SQLExpress) running service:
"C:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Binn\sqlservr.exe"
-sSQLEXPRESS
--
bruno


[quoted text, click to view]
stcheng NO[at]SPAM online.microsoft.com
8/24/2006 2:36:22 PM
Thanks for the reply Bruno,

Based on your last reply:

================
actually I solved the problem applying one of the two solutions given in
the
document you suggested -->
http://aspadvice.com/blogs/plitwin/archive/2005/11/04/13590.aspx.
I changed the web.config, with a remove and add name="LocalSqlServer".
Now it works, I can access Security tab in ASP.NET Web Site Administration
Tool. But in the web.config I had to specify: connectionString="Data
Source=localhost\SqlExpress ... instead of connectionString="Data
Source=localhost, as reported in the Paul Litwin's Blog (??).
===================

This means you can get the ASP.NET provider to connect a database in the
pre-attached SQL Express database engine rather than a dynamically attached
(user instance) file(in App_Data directory).

also, as you mentioned, you can not create a new sql express database
file(mdf) in VS 2005, it seems there is something incorrect with the SQL
Express installation. Because when using the default provider
connectionstring, it will try creating such as mdf file (in app_data) also,
and your current installation seems can not finish this.

I suggest you consider reinstalling SQL Express first, if still not work,
we may also have to reinstall VS 2005 together.

Please feel free to let me know if there is anything else we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
bruno
8/25/2006 12:53:01 AM
reinstalling SQL Express solved the problem.
Many thanks
--
bruno


[quoted text, click to view]
Brian J. Matuschak
11/21/2006 4:37:01 PM
Thanks to both of you for taking time to post. I had exactly the same
problem, and I had to use "LOCALHOST\SQLEXPRESS" to get it to work since I
have multiple instances of SQL Server on my machine.
--
Brian J. Matuschak
brian@electronic-atlas.com


[quoted text, click to view]
AddThis Social Bookmark Button