ASP.NET Attempt to attach auto-named a database failed? - asp.net

Parser Error Message: An attempt to
attach an auto-named database for file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data\aspnetdb.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
Why could this be happening? My connection string doesn't use |DataDirectory|, it is:
<connectionStrings>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>
I get this error when I try to load default.aspx, after installing BugNET.

Apparently, and certainly for some obscure reason. There is a mistery connection string coming from... nowhere.
Problem solved adding a <clear/> tag.
<connectionStrings>
<clear/>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>

file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data**aspnetdb.mdf**
failed.
This is the ASP.NET standard membership system here - not your "regular" database. There must be a second connection string somewhere that references this aspnetdb.mdf and tries to attach it from a file.
Search your solution for this file name - it must be somewhere!

Related

Getting error An invalid dn syntax has been specified with AspNetActiveDirectoryMembershipProvider

My configuration is as follows:
<connectionStrings>
<add name="ADService" connectionString="LDAP://myserver.com:636/ou=people,dc=mysite,dc=com" />
</connectionStrings>
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
<providers>
<add name="AspNetActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADService"
attributeMapUsername="uid"
attributeMapEmail="mail"
connectionProtection="Secure"
/>
I have verified the connection string it works and returns the objects with uid=xxx . But with ASP.net I am recieving error
Parser Error Message: An invalid dn syntax has been specified.
My Ldap server support anonymous binding. What am i doing wrong ? The server I am connecting to is not AD but an OpenLDAP 3.0 .
When do you get the error? i.e. What part of your code? Invalid dn syntax can be thrown for a couple of reasons: like problem with the connection string or invalid characters like comma in a property while you are retrieving it.
Btw: attributeMapUsername="uid"? Are you sure about this? Why not attributeMapUsername="userPrincipalName"? or attributeMapUsername="sAMAccountName"?
It was an LDAP configuration issue. It required an SSL connection which I was not doing. It needed AuthenticationTypes.SecureSocketsLayer | AuthenticationTypes.FastBind in the connection option.
On the other note, this built in api only works for AD so I had to write my own.

Invalid value for key attachdbfilename

I try to run my asp net application in godaddy webserver and get error:
Exception Details: System.ArgumentException: Invalid value for key ‘attachdbfilename’.
My connection string:
<connectionStrings>
<remove name=”LocalSqlServer”/>
<add name=”LocalSqlServer” connectionString=”Data Source=(LocalDB)v11.0;Integrated Security=True;AttachDbFilename=|DataDirectory|Database.mdf” providerName=”System.Data.SqlClient”/>
</connectionStrings>
Any ideas how could I fix this? I dont have this error on my pc.
Ooops, I had the same problem, in my case i did not have LocalDB installed, so how about you check for that!!

Environment variables in ASP.NET web.config file

I was wondering why can't I use a custom environment variable in an ASP.NET web.config file like so?
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ConnectionName" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename='%MyProjectsFolder%\WebAppName\App_Data\Database1.mdf';User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I checked through Start -> Run that the file path to .mdf file is valid.
When I run my C# code to connect to database I get the following error:
An attempt to attach an auto-named database for file
%MyProjectsFolder%\WebAppName\App_Data\Database1.mdf failed. A
database with the same name exists, or specified file cannot be
opened, or it is located on UNC share.
Environment variables may not be used in a config file.
You can use: DataDirectory like this:
“Data Source = |DataDirectory|\Mydb.sdf”
And you can change where DataDirectory points: "To set the DataDirectory property, call the AppDomain.SetData"
http://social.msdn.microsoft.com/Forums/en/sqlce/thread/dc31ea59-5718-49b6-9f1f-7039da425296
Caveat, I've never tried this.
I don't suppose you've tried:
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename='~/App_Data/Database1.mdf';User Instance=true"

Pre-Generating views to improve query performance in Entity Framework

I am trying to pre-generate view metadata for my Entity Framework project and have run across a problem on the last step when using this resource:
http://msdn.microsoft.com/en-us/library/bb896240.aspx
Everything else is compiling great, but I'm getting an error when I run my application, and I suspect it's due to a problem with the final step, 're-adding mapping and model files as embedded resources for ASP.NET projects.'
I'm receiving 'Unable to load the specified metadata resource.' and my connection string is as follows:
<add name="myEntities"
connectionString="metadata=
.\DataStructure.csdl|
.\DataStructure.ssdl|
.\DataStructure.msl;provider=System.Data.SqlClient;provider
connection string="Data Source=x;Initial Catalog=x;Persist Security Info=True;User ID=x;Password=x;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
It is suggested in the document that my connection string file should include the following but haven't been able to get it right in any configuration:
Metadata=res://<assemblyFullName>/<resourceName>;
Metadata=res://*/<resourceName>;
Metadata=res://*;
Assuming my assembly name is DataStructure.EF, how should my string be constructed?
http://msdn.microsoft.com/en-us/library/cc716756.aspx
<connectionStrings>
<add name="AdventureWorksEntities"
connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
</connectionStrings>
I compiled a full guide for anybody else having problems and published it here: http://kewney.com/posts/software-development/pre-generating-views-to-improve-query-performance-in-aspnet-mvc-3-entity-framework

Membership provider name and type for Microsoft WebMatrix's sample Template

What is the membership provider name and type is used in the Microsoft Webmatrix's template site? In the web.config it is not given. When I run it locally, the template works but when I publish, it gives the following error:
Parser Error Message: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty.
Source Error:
Line 239: <providers>
Line 240: <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, ....
Source File: C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config Line: 240
Any help will be appreciated.
The Database used in the application is SQLCE4.
Web Pages uses the SimpleMembershipProvider which is located in WebMatrix.WebData.
I don't believe there's a default Membership provider that supports SQL Server Compact Edition 4. There is a Membership provider implementation that does out on CodePlex: http://sqlcemembership.codeplex.com/
So, if you're using that already, then ensure that you have a connection string defined in your config file, like so:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="data source=|DataDirectory|\YourDatabaseName.sdf"/>
</connectionStrings>
And your provider specified in your config should define the connectionStringName attribute and reference the connection string's name defined in the <connectionStrings> block, like this:
<providers>
<clear/>
<add name="SqlCeMembershipProvider"
type="ErikEJ.SqlCeMembershipProvider"
connectionStringName="LocalSqlServer"
.... />
</providers>
A config sample is provided with that SQL CE 4 Membership provider on the main project page.

Resources