Abdullah Almrhabi
Abdullah Almrhabi

Reputation: 1

Change .mdf local database and transfer to SQL Server 2014 with user sa .. later on I want to upload my project to hosting or iis host

I have faced issues after finish my ASP.NET MVC & Entity Framework project.

I have changed the connection string and point to my SQL Server with user sa to generate the database.

I get this error:

System.Data.SqlClient.SqlException: 'Cannot find the object "dbo.Comments" because it does not exist or you do not have permissions.'

When I return to the local connection string, everything is working fine again.

Local connection string

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDb)\MSSQLLocalDB;
                           AttachDbFilename=|DataDirectory|\aspnet-ElectronicHarajPro-20200323090456.mdf;
                           Initial Catalog=aspnet-ElectronicHarajPro-20200323090456;
                           Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>
  

SQL Server connection string:

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDb)\MSSQLLocalDB;
                           Server=MININT-3V9GJ88;
                           Database=ElectronicHarajPro;
                           User Id=sa;Password=123456;
                           Integrated Security=false" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Upvotes: 0

Views: 110

Answers (2)

Abraham Qian
Abraham Qian

Reputation: 7522

There is something wrong with your new connection string. We either use DataSource or Server property to specify the SQL server database instance in the connection string. I suggest you construct the connection string by using SQL Server Object Explorer in Visual Studio.
enter image description here
enter image description here
enter image description here
About the Microsoft SqlClient Data Provider for SQL Server connection string, please refer to the below documentation.
https://www.connectionstrings.com/microsoft-data-sqlclient/
Feel free to let me know if there is anything I can help with.

Upvotes: 0

marc_s
marc_s

Reputation: 754368

Your server-based connection string contains two conflicting entries - one for Data Source= (pointing to the local SQL Server LocalDB instance), another for server= (which I guess is the SQL Server machine).

You need to ensure you use only one of those two!

Try this :

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Server=MININT-3V9GJ88;Database=ElectronicHarajPro;
                           User Id=sa;Password=123456;Integrated Security=false" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Upvotes: 1

Related Questions