0

I am trying to have access to my project from the browser, I have put it on my server .

My database is on SQL Server 2008 R2 .

When I try to login I have always this exception :

Invalid value for key 'attachdbfilename'

I think the problem is from my connection string but I can't fix it . I tried in many ways .

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

Can someone help me ?

Thank you very much .

1

3 Answers 3

3

The AttachDbFileName= feature is available ONLY in the SQL Server EXPRESS edition. It is NOT compatible and supported on a "full" SQL Server installation.

If you have a full SQL Server, you have to attach your database to the SQL Server instance, and then reference it by its (logical) database name - not the physical file name:

<connectionStrings>
  <add name="LocalSqlServer" 
       connectionString="server=.;database=DataUi;Integrated Security=SSPI;"
       providerName="System.Data.SqlClient" />
 </connectionStrings>
Sign up to request clarification or add additional context in comments.

Comments

1

You should "Database" rather than "AttachDbFileName" as it is not recommended for production servers.

Hence your connection string should be:

<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Initial  
Catalog=DataUi;Integrated Security=SSPI;Database=DataUi.mdf;User  
Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>

2 Comments

I have just put this . <connectionStrings> <remove name="LocalSqlServer" /> <add name="LocalSqlServer" connectionString="data source=BESPIN\SQLEXPRESS;Database=DataUi.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> And now I get this strange error : System.Data.SqlClient.SqlException: Login failed for user ''.
does your user have permissions to access the SQL Server. Also check if the user has permissions to access the database and what commands are allowed on the database.
0

I think there's a missing \\ in your AttachDBFilename right after |DataDirectory|:

AttachDBFilename=|DataDirectory|\\DataUi.mdf

2 Comments

I can't have access with 2 \\ . And I got the same error with \ .
I have just put this . <connectionStrings> <remove name="LocalSqlServer" /> <add name="LocalSqlServer" connectionString="data source=BESPIN\SQLEXPRESS;Database=DataUi.mdf;User Instance=true" providerName="System.Data.SqlClient" /> </connectionStrings> And now I get this strange error : System.Data.SqlClient.SqlException: Login failed for user ''.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.