2

Actually, i wanted to check is my connection string valid.

There are asp.net mvc web app and mysql db deployed on azure, so i want use second thing in first. So, i added db to visual studio server explorer - db and all tables are visible.

Now i tried to add connectionstring to my project, and, wow, there are two of them i found: First: In Visual studio data connection properties:

server=us-cdbr-azure-central-a.cloudapp.net;user id=userid;persistsecurityinfo=True;database=crawlerdb

Second: In azure workplace's database property:

Database=CrawlerDB;Data Source=us-cdbr-azure-central-a.cloudapp.net;User Id=userid;Password=userpass

And both of them doesn't work. Never lucky. Connection state checking code:

using (SqlConnection conn = new SqlConnection(connstr))
        {
            try
            {
                conn.Open();
                var q = conn.State;
            }
            catch(Exception ex)
            {
                var q = ex.Message;
            }
        }

What am i doing wrong?:) Tell me plz:)


public class CrawledDataContext : DbContext
{
    public CrawledDataContext()
    {
        Database.SetInitializer<CrawledDataContext>(null);
        using (SqlConnection conn = new SqlConnection("server=us-cdbr-azure-central-a.cloudapp.net;user id=bb15193d20f901;persistsecurityinfo=True;database=crawlerdb"))
        {
            try
            {
                conn.Open();
                var q = conn.State;
            }
            catch(Exception ex)
            {
                var q = ex.Message;
            }
        }
    }
    public DbSet<GroupInfo> GroupInfoes { get; set; }
}

Here is exception message:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

4
  • Where do you read your connection string from in your code? Commented Nov 3, 2015 at 0:53
  • Actually, i'm using dbcontext, so i added code above into overrided dbcontext class ctor. Commented Nov 3, 2015 at 1:12
  • without seeing full method of how you overriding dbcontext it is hard to tell. Do you get any exceptions? Commented Nov 3, 2015 at 2:06
  • added code to question Commented Nov 3, 2015 at 15:05

1 Answer 1

2

SqlConnection is for SQL Server Databases. you should use MySqlConnection instead.

using (MySqlConnection conn = new MySqlConnection("server..."){}
Sign up to request clarification or add additional context in comments.

1 Comment

Whoa, that nice, actually question i asked is answered:)

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.