Reputation: 75
I am trying to write a very simple C# Script that establishes a connection to my Azure SQL Database.
using System;
using System.Data.SqlClient;
namespace first_project
{
class MainClass
{
public static void Main(string[] args)
{
var cb = new SqlConnectionStringBuilder();
cb.DataSource = "server.bloo.blah.foobar";
cb.UserID = "user@database";
cb.Password = "secret";
cb.InitialCatalog = "database";
using (SqlConnection connection = new SqlConnection(cb.ConnectionString))
{
try
{
connection.Open();
Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
Console.WriteLine("State: {0}", connection.State);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
}
}
}
From what I have gathered online, this code should be working? However, I am getting the following error
System.AggregateException: One or more errors occurred. ---> System.IO.IOException: Unable to read data from the transport connection: Operation on non-blocking socket would block. ---> System.Net.Sockets.SocketException: Operation on non-blocking socket would block
Could anyone enlighten me on what is going on? Thanks in advance.
Upvotes: 0
Views: 325
Reputation: 21
In your connection, instead of cb.UserID = "user@database" use cb.UserID = "user"
That should work.
Upvotes: 0
Reputation: 1527
First the SQL database has a firewall. You have to add your IP through the azure portal.
Secondly make sure your connection string is correct you can look at another sample online. I remember having syntax errors as well, just copy the string that azure gives you.
Upvotes: 1