C# Linq to SQL connection string (newbie)

Posted by Chris'o on Stack Overflow See other posts from Stack Overflow or by Chris'o
Published on 2012-07-02T01:56:21Z Indexed on 2012/07/02 3:16 UTC
Read the original article Hit count: 191

Filed under:
|
|
|
|

i am a new linq to sql learner and this is my very first attempt to create a data viewer program. The idea is simple, i'd like to create a software that is able to view content of a table in a database. That's it.

I got an early problem here already and i have seen many tutes and articles online but I still cant fix the bug.

Here is my code:

    static void Main(string[] args)
    {
        string cs = "Data Source=localhost;Initial Catalog=somedb;Integrated Security=SSPI;";

        var db = new DataClasses1DataContext(cs);
        db.Connection.Open();

        foreach (var b in db.Mapping.GetTables())
            Console.WriteLine(b.TableName);

        Console.ReadKey(true);
    }

When I tried to check db.connection.equals(null); it returns false, so i thought i have connected successfully to the database since there is no error at all. But the code above doesn't print anything out to the screen.

I kind of lost and don't know what's going on here. Does anyone know what is going wrong here?

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql