I have tried some five tutorials.
See the code in C #
string minhaString = "Server=.\sqlexpress;Trusted_Connection=true;" +
"Timeout=10;" +
"Database =bdcadastro;";
SqlConnection minhaConexao = new SqlConnection(minhaString);
try
{
minhaConexao.Open();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine("Versão do servidor: " + myConnection.ServerVersion);
}
The code runs and returns the version of the server.
VB.NET:
Dim minhaString As String = "Server=.\sqlexpress;" &
"Trusted_Connection=true;Timeout=10;Database=bdcadastro;"
Dim minhaConexao = New SqlConnection(minhaString)
Try
minhaConexao.Open()
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
Console.WriteLine("Server version is: " + myConnection.ServerVersion)
End Try
As I'm using the same library, I assumed it would work the same, but in VB.NET it returns me Instance Failure
and throws an exception of type InvalidOperationException
on line
Console.WriteLine("Server version is: " + myConnection.ServerVersion)
Why?