Solved

how to make link data structures rebuild

Posted on 2011-03-20
11
333 Views
Last Modified: 2013-12-17
In Visual Studio 2010 using C#, when I used linkdatasource objects, it created some automatically generated files in App_Code ( .dbml files).

Now I'm returning to an old project, and the designs of the tables in the database have changed. I'm getting errors because the automatically generated linkdatasource info is not matching the database.

How do I make the object refresh itself from the database (rather than continuing to use its old models)?

Sorry I don't know the right names for these objects. Feel free to introduce the topic a little if you understand the concepts.
0
Comment
Question by:JeReLo
  • 6
  • 5
11 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 35175470
Hi JeReLo;

There is no automatic refresh to update the model. What you need to do is to open the DBML file in the designer. Then in Server Explorer right click on the database that contains the tables that have changed, and select the Refresh item from the context menu. View the tables that have changed to make sure that the new columns are now displayed. Now delete the tables that changed in the designer and then select and drag the tables back from Server Explorer. Now the model has been updated.

Fernando
0
 

Author Comment

by:JeReLo
ID: 35177538
Great answer Fernando, I was able to do it.
May I ask a related followup question?

I am setting the connection string in the web.config fie and I'd like the designer to use that connectionstring, but it insists on using it's own. For example, my connection string uses tcp but the designer will use namedpipes when I use the server explorer.

How can I get designer to use my connection string? I tried just editting it, but then the designer complains "The connection property in the web.config file is missing or incorrect. The connection string from the .dbml file has been used in its place."

It then edits my config file (adding the 1 as below):
  <add name="pathsConnection" connectionString="Type System Version=Latest; Network Library=DBMSSOCN; Connect Timeout=5; server=x.x.x.x;  Initial Catalog=paths;  User ID=x; Password=x"
    providerName="System.Data.SqlClient" />
  <add name="pathsConnectionString1" connectionString="Data Source=CORE;Initial Catalog=paths;User ID=x"
    providerName="System.Data.SqlClient" />

Is this normal? Is it preventable?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35177598
Hi JeReLo;

You can read the connection string from the web.config file into a string variable and then when you instantiate the data context pass it in as a parameter.

String conStr = // command that reads the connection string from web.config;
DataContextClass db = new DataContextClass( conStr );

Sorry I am not by my computer right now and I am using a mobile device so if you need help getting the connection string from the web.config file into your program I will be able to that when I get back tonight. So let me know if you need that.

Fernando
0
 

Author Comment

by:JeReLo
ID: 35178460
That would be great if you could send the code to read in a specified connection string from web.config.

I don't know if this will confuse things or help to clarify the context, but I use a seperate file for connection settings, via this line in web.config

  <connectionStrings configSource="host\HNPS.config"/>

So the connection string is stored in "host\HNPS.config"
and its given a name like this  <add name="pathsConnection" connectionString= etc.

thanks.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35182294
Hi JeReLo;

Here you go.

// This gets the connection string from the web.config file. 
// The syatem will merge the host\HNPS.config with web.config so access is the
// same with or without the extra file.
ConnectionStringSettings myConn = ConfigurationManager.ConnectionStrings[ "pathsConnection" ];
// Now pass the connection string to the DataContext as a parameter and thats it.
DataClasses1DataContext db = new DataClasses1DataContext( myConn.ConnectionString );

Open in new window


Fernando
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:JeReLo
ID: 35187677
Thanks for the code Fernando. As is often the case in learning, I found it hard to ask the question to solve the problem I had. The question you answered however, was enough to move me towards solving the problem.

I found the line I needed to edit in the related designer.cs page. When I used my preferred connectionstring name there, then the designer loaded fine.


	public pagevisitsDataContext() :base(global::System.Configuration.ConfigurationManager.ConnectionStrings["pathsConnection"].ConnectionString, mappingSource)

Open in new window


All's well!
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35189514
Hi JeReLo;

Glad to hear that all is well. Can you please close the question.

Thank you;
Fernando
0
 

Author Comment

by:JeReLo
ID: 35196929
I'm terribly sorry, but I've scanned up and down this page, and the interface is not providing sufficient indication of where I could close the question.

Would you mind giving some indication of where to close it? Can you also confirm you got the points?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35199121
Hi JeReLo;

It is not a problem. Log in to your EE account and then come to this page, you will most likely be logged in already. Then go to the comment which best answered your question and in that comment box there should be a button or link that states Accept as Answer or somthing to that effect. That should bring you to a question about assigning points. Once points have been assign the question will be closed.

Fernando
0
 

Author Comment

by:JeReLo
ID: 35202336
thanks, done.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 35202831
Thank you.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now