Subject: I can't connect to the sql 2005 developer DB
Posted By: gulfpaddler Post Date: 9/16/2006 12:19:37 PM
I am working on the Online Diary Project.  I have modified the actual connection in databse explorer to use sql 2005 (not express)and modified the connection string in the web.config.  This is the connection string:  

 <add name="DiaryDBConnectionString" connectionString="Data Source=THEO;Initial Catalog=Diarydb.mdf;Integrated Security=True"
   providerName="System.Data.SqlClient" />

Can someone tell me where I am going wrong, please?  

I am guessing that it is something in ASP that I am missing. Thanks

An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


Reply By: Imar Reply Date: 9/16/2006 1:21:05 PM
Hi there,

How is your SQL Server installation called? And is it located on the same machine as your web app?

Can you give us a bit more details about your setup?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: gulfpaddler Reply Date: 9/16/2006 2:35:04 PM
Hi, thanks for responding.

Both, the web app and DB are on the same machine.  I am using windows authentication.  

I just added a line including impersonation- - I get the same results.  

I have run other web/wDB apps before on this machine.  I a version 4 of DNN running.  

Here is my web.config. Maybe it will help.

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    <connectionStrings>
  <add name="DiaryDBConnectionString" connectionString="Data Source=THEO;Initial Catalog=Diarydb;Integrated Security=SSPI"
   providerName="System.Data.SqlClient" />
 </connectionStrings>
 <system.web>
   <identity impersonate="true" />
   <roleManager enabled="true" />
  <authentication mode="Forms"/>
        <compilation debug="true"/></system.web>
 <system.net>
  <mailSettings>
   <smtp from="system@diary-system.com">
    <network host="localhost" password="" userName= ""/>
   </smtp>
  </mailSettings>
 </system.net>
</configuration>



Reply By: gulfpaddler Reply Date: 9/16/2006 2:42:28 PM
I have attempted the connection on both the IIS and built in web server.

Reply By: gulfpaddler Reply Date: 9/16/2006 5:35:50 PM
After looking a little close to this problem, it seems that my problem is with the aspnetdb.mdf.  I can see how to move the db to sql 2005 but I can't see where to call it from.  All along I thought that the diarydb was not connecting, but I think now that the problem is aspnetdb.mdf.  I really need some direction now, please.  Thanks

Reply By: Imar Reply Date: 9/17/2006 5:40:17 AM
Hi there,

Take a look at this article: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=395

It explains how to configure ASP.NET apps and SQL Server to allow your apps to use a commercial version of SQL Server instead of the Express Edition. I think it provides all the guidance you may need.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Shadowplay (RCA Unreleased Album Session - Arrow Studios, Manchester, May 1978) by Joy Division (Track 7 from the album: Heart And Soul (CD 3 - Studio Rarities & Unreleased)) What's This?
Reply By: gulfpaddler Reply Date: 9/17/2006 1:07:48 PM
You know that may be some of the problem, but I don't think that it is the central problem.  In the online diary application, you must first login before you can do anything.  The Aspnetdb.mdf controls the login, and the connection string for this login is to sql express, not sql 2005!  I believe that the connection string for this paticular db is in the machine.config file, because it is certainly not in web.config. Now this change is going to trigger a series of changes.  May I recommend that you go to your online coding depository and provide a version of the code for sql 2005 databases. This would be the quickest way to solve this problem. Then once I am sure that I have a correct connection string to sql 2005, I can then focus my attention on ASP permissions.  I don't want to rant, buy why would you write a book based on sql express (and exempt sql 2005) when the developer edition of SQL 2005 cost less than $50. With this bargin of a price, I can't understand why anyone would use sql express.  Thanks

Reply By: gulfpaddler Reply Date: 9/17/2006 2:24:47 PM
This code is in the machine.config file. It points the aspnetdb.mdf to sql express. This code appears to control all of the membership and role providers.  Should I manually change this?  And, once I change it, will it correctly point to the aspnetdb.mdf. Will this connection string work: connectionString="Data Source=THEO;Initial Catalog=aspnetdb.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />?
Do I have to reclocate the actual databases to some other directory, also?  How did this code get here?  This is starting to look like a lot of work.  Thanks  

<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.data>
    <DbProviderFactories>
      <add name="Odbc Data Provider" invariant="System.Data.Odbc" description=".Net Framework Data Provider for Odbc" type="System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <add name="OleDb Data Provider" invariant="System.Data.OleDb" description=".Net Framework Data Provider for OleDb" type="System.Data.OleDb.OleDbFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <add name="OracleClient Data Provider" invariant="System.Data.OracleClient" description=".Net Framework Data Provider for Oracle" type="System.Data.OracleClient.OracleClientFactory, System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      <add name="SqlClient Data Provider" invariant="System.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </DbProviderFactories>
  </system.data>
  <system.web>
    <processModel autoConfig="true" />
    <httpHandlers />
    <membership>
      <providers>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
      </providers>
    </membership>
    <profile>
      <providers>
        <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </profile>
    <roleManager>
      <providers>
        <add name="AspNetSqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <add name="AspNetWindowsTokenRoleProvider" applicationName="/" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>

Reply By: Imar Reply Date: 9/17/2006 3:19:17 PM
Hi again,

Why would anyone spend $50 if you can get most of SQL Server for free?

Anyway, that's not really the point here. The thing is, there is no "code for SQL Server 2005" and "code for the Express Edition". Switching between the two is a matter of configuration.

The first article I linked to fixes issues with your own databases that run under SQL Server. Did you see / follow the link from that article to the blog post by Scott Guthrie? It explains how to configure the ASP.NET services (like Membership) to work with a real version of SQL Server. You can find the post here: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

Basically, all you need to do comes down to this:

1. Configure a database for ASP.NET 2 services.

2. "Clear" existing connection strings from the config hierarchy

3. Add a new one that points to your server.

That's it. No messing around with machine config, no special code and so on. The article explains in detail what you need to do.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: gulfpaddler Reply Date: 9/17/2006 7:55:53 PM
Fine, I guess you didn't like my recommendation about providing code for both db scenarios.  Actually I still think that it is a pretty good idea and you should consider it, for had I known when I bought the book that it was based on sql express, I would not have bought it.  I bought the book on Amazon.com and this parcel of information wasn't revealed.
  
Re your position about getting most (but not all) of something, that's pretty close to where I am with the code in your book.  You have provided most of what I need, but not all, yet that very small missing part is making all the difference in maybe having had an app running two days ago vs still not running, while I still rummage throught the internet for some cryptic instructions on how to re configure an application from the economy version to the standard comercial version.

Furthermore, I am speaking with some degree of experience about the difference in the two versions: I used sql express for 4 months on one of my three machines and was constantly running into work that it couldn't do, but that it predecessor, sql 2000 could. Since upgrading to sql 2005 this has not been an issue.  There is unequivocally no comparision in the difference between using express and the full blown developer edition: I repeat no comparison!

So far this whole endeavor has been a real dissappointment. Now, the silver lining to all of this is that I am getting very granular look a configuring different databases.  Not that I wanted to or that I should have ever needed to.   It looks like I am on my own with this problem and will have make a decision whether to continue with the other projects in the book or move on to another text.

In closing please take all of this in the constructive spirit in which I have offered it.Thanks again, JB

Reply By: Imar Reply Date: 9/18/2006 1:43:22 AM
Hi gulfpaddler,

Well, I guess there is some confusion here.... It's not that I don't like your recommendation, it's that I don't know what code you want me to provide.

There's no need for two different code bases for the application. The code that comes with the book runs on Express and other versions of SQL Server without a change.

The only difference is the web.config file and the settings for the services and connection strings. I'll be more than happy to explain how to do this and provide a new web.config file, but I don't think I can do it any better than Scott can do it... The article I linked to explains how to do this step by step. But, if there's something you want me to do let me know.

If you look at some of the posts in the book's forum, you'll see that we do try to help wherever we can, trying to provide the information and help that people need. But, obviously, we can only provide something if we understand what it is that you need.... ;-)

So, all in all, if you could detail your recommendation a little further, I am more than happy to help you....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Reply By: bex Reply Date: 8/3/2008 1:32:01 PM
hi you need to change the connection string inside the classes in the app-code folder, wich i don't now how to? does any one know?

bx
Reply By: Imar Reply Date: 8/3/2008 1:34:47 PM
Eum, aren't we doing this here already? http://p2p.wrox.com/topic.asp?TOPIC_ID=73212

Please don't crosspost; makes things much harder for everyone.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
Reply By: bex Reply Date: 8/3/2008 2:07:05 PM
yes we are

bx
Reply By: vspuni Reply Date: 8/8/2008 10:08:22 AM
Hi Imar,
Recently I bought this book and trying to run the "Online Diary" example and got into this issue.
I have VS.NET 2005 and SQL Server 2005 installed in the same system (my laptop).
As it is mentioned here, I have attached a new database to "DIARYDB.MDF" file and changed my connection string in web.config file.  I am not sure it is required or not, I have changed the connection strings in all the 4 places in .vb files in app_code folder as it is changed there in web.config file.
Also I have run "aspnet_regsql.exe" on DIARYDB database.
Still I am getting the following error:
An error has occurred while establishing a connection to the server.  When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I am not using any remote SQL Server, I don't understand how to fix this issue.

Do I need to do any thing with the ASPNETDB.MDF available in app_data folder also?

Please reply.

Regards,
PVS

quote:
Originally posted by Imar

Hi again,

Why would anyone spend $50 if you can get most of SQL Server for free?

Anyway, that's not really the point here. The thing is, there is no "code for SQL Server 2005" and "code for the Express Edition". Switching between the two is a matter of configuration.

The first article I linked to fixes issues with your own databases that run under SQL Server. Did you see / follow the link from that article to the blog post by Scott Guthrie? It explains how to configure the ASP.NET services (like Membership) to work with a real version of SQL Server. You can find the post here: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx

Basically, all you need to do comes down to this:

1. Configure a database for ASP.NET 2 services.

2. "Clear" existing connection strings from the config hierarchy

3. Add a new one that points to your server.

That's it. No messing around with machine config, no special code and so on. The article explains in detail what you need to do.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.

Reply By: tinie8642 Reply Date: 8/12/2008 2:50:24 AM
Hi there,

Just wanted to be sure. I did download chapter 11 - greeting cards to explore the codes and learn a little bit about it. all codes and display of this greeting cards website is wonderful except when i tried to send the email. i have configured the smtp mail configuration like the book said but when i debug the website, it show one line of codes that stated the "The specified string is not in the form required for an e-mail address."

I'm using microsoft visual basic 2008 and also the sql server 2005. I'm eager to know what is the main problem of the code since all of the page are wonderfully success except for the email part. I will show the codes below for your references. I'm really wanted to know so that i can continue the studies of this website because i'm doing quite similar web site which allow user to design their own ideas in the web themselve. Hope you can reply and help me.

Dim myMailMessage As New MailMessage()
that is the code in default.aspx.vb page stating "The specified string is not in the form required for an e-mail address." and also "FormatExecption was unhandled by user codes"

Hope to have your reply. Thanks.

p/s : is there any new codes in asp.net 3.5 for the connection string in web.config? I'm having lots of trouble connecting the database.
Thanks.

Regards,
Tinie8642

Motivation is Important! Do not act if you're not sure.
Reply By: Imar Reply Date: 8/21/2008 4:17:46 AM
Hi vspuni,

Sorry for the late reply; I was away for holidays.

Are you still having problems with this? Where are your databases stored (physically) and how do your connection strings look?

@tinie8642: sounds like you are passing an empty or invalid e-mail address. What exactly are you doing / passing?
BTW: can you start a new thread for a new topic? This one dealt with SQL Server, not e-mail which makes it difficult to track and read for everyone.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.

Go to topic 73585

Return to index page 1