How to fix "ServerVersion" threw an exception of type "System.InvalidOperationException"?

I have a local SQL Server database, and I'm trying to connect to it apparently unsuccessfully:

new SqlConnection(@"Server=(localdb)\v12.0;Integrated Security=true;Database=MyDBName;");

However, this line throws an exception: "ServerVersion" throws an exception of type "System.InvalidOperationException"? What can I do to fix this?

I ran

sqllocaldb create "v12.0"

but it doesn't seem to matter.

enter image description here

enter image description here

+4
source share
2 answers

Try to take a look at how you open the connection. Have you tried something like this: C # Console Application Invalid Operation Exception

+1

:

private void connection()
{
    con = new SqlConnection(ConfigurationManager.ConnectionStrings["conStrSheebu"].ConnectionString);
}

web.config :

<connectionStrings>
    <add name="conStrSheebu" connectionString="Data Source=(local);Initial Catalog=Sheebu;User ID=sa;Password = AnsarI" providerName="System.Data.SqlClient" />
</connectionStrings>
-1

Source: https://habr.com/ru/post/1612762/


All Articles