error: 40 hell

error: 40 hell

Old forum URL: forums.lhotka.net/forums/t/5527.aspx


eulerthegrape posted on Friday, October 03, 2008

I have been working with two .mdf local database files for over a month.  Today, when I tried to open the database in Visual Studio's Server Explorer, it balked at me and threw a error: 40 at me.  The whole message says:

An error has occurred while establishing a connection to the server.  When connection to SQL Server 2005, this failure may be cause by the fact that under the default settings SQL Sever does not allow remote connections. (provider: shared memory provider error: 40 - could not open a connection to SQL Sever)

Now this happened to me once before when I was moving files and, if I remember correctly it had something to do with a configuration file.

I have two app.config files in three projects one in a database project:
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
    <connectionStrings>
        <add name="CasasDB.Properties.Settings.CasasConnectionString"
            connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename='|DataDirectory|\Casas.mdf';Integrated Security=True;User Instance=True"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

and the other a prject containing forms

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=14037268209d3bd5" >
      <section name="Csla.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=14037268209d3bd5" />
    </sectionGroup>
  </configSections>
  <appSettings>
    <add key="CslaAuthentication" value="Csla"/>
  </appSettings>
  <connectionStrings>
    <add name="Casas" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Casas.mdf;Integrated Security=True;User Instance=True" />
    <add name="Security" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Security.mdf;Integrated Security=True;User Instance=True" />
  </connectionStrings>
</configuration>

Currently I cannot create a new database let alone access the ones that already exist.

I think there is something else screwy with my work station because it's been acting wonky and there seems to be no rhyme or reason why, all of a sudden, I wouldn't be able to access these databases.

Any suggestions?  Is the a problem with a setting in Visual Studio or a config problem or something I haven't mentioned perhaps?

Thank you,
euler

eulerthegrape replied on Friday, October 03, 2008

Well, I started up the SQL Server (SQLEXPRESS) service in the SQL Server Configuration Manager and that allowed me to access the database from the server explorer.  This is weird because I never had to start this process in the past.  Unfortunately, I now see the following error:

DataPortal.Fetch failed (An attempt to attach an auto-named database for file [filepath]\Database.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.)

Thanks in advance for any help

eulerthegrape replied on Friday, October 03, 2008

Ok.  I changed the app.config file so that it is the explicit file path and this has solved the issue.  Although, now I'm not using |DataDirectory|, which I would like to.  It also doesn't answer why the SQL Express process needed to be started in the Configuration Manager.

Has anyone else seen these issues?

Copyright (c) Marimer LLC