none
Connect To Linq DataContext Problem RRS feed

  • Question

  • I used Linq to sql to connect a remote sql server 2000 .
    All is ok .

    Today I generate the sql script from the remote sql server of each table .
    And execute this script in my local sql server express .
    All is ok .

    When I use the local database(my local sql server express) connection string to init the linq datacontext , it will be fine.
    But when execute any sql or linq query via that DataContext , will throw a exception " Invalid Object Name 'XXXX"(XXXX is actuly is Linq DataContext Name)

    My question is :

    My linq to sql DataContext was generated by the remote sql server , even I copy/clone the remote database schema to my local database  , and even the linq datacontext can init itself . When I actually execute any query it still will be throw exception .
    Does it right ????
    if yes , could someone give me any advice how to solve the problem like my scenario ???

    What I want is :
    Use the same linq data context , and make it connect to servcal database according to the connection string .

    Thanks a lot .





    Wednesday, October 15, 2008 11:35 AM

Answers

  • Does your connection string specify the database name?  If it does not (maybe it relies on server defaults), then the DataContext will attempt to switch to the database by name that it knows from the mapping. If the database name is not in the mapping it will fall back to the name of the DataContext class.

     

    You can avoid any/all of this behavior by creating your DataContext with an already open connection object.

     

     

     

    Wednesday, October 15, 2008 3:58 PM
    Moderator

All replies

  • Does your connection string specify the database name?  If it does not (maybe it relies on server defaults), then the DataContext will attempt to switch to the database by name that it knows from the mapping. If the database name is not in the mapping it will fall back to the name of the DataContext class.

     

    You can avoid any/all of this behavior by creating your DataContext with an already open connection object.

     

     

     

    Wednesday, October 15, 2008 3:58 PM
    Moderator
  • Thanks Matt Warren .
    That's exactly my problem.
    After I specified the database name of connection string . it work fine.

    Thank you so much .
    Thursday, October 16, 2008 2:30 AM