Solved

how to make link data structures rebuild

Posted on 2011-03-20
11
323 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:JeReLo
Comment Utility
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
Comment Utility
Hi JeReLo;

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

Thank you;
Fernando
0
 

Author Comment

by:JeReLo
Comment Utility
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
Comment Utility
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
Comment Utility
thanks, done.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Thank you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

16 Experts available now in Live!

Get 1:1 Help Now