U.S. stocks rose modestly on Wednesday after a Federal Reserve survey said the economy has gained strength, but oil prices near 2-1/2 year highs weighed on the market.

The Dow and the S&P 500 at one point turned negative as Brent crude rose above $117 a barrel after bombing raids struck near Libya's oil terminals.

But the market calmed down, and the Fed's Beige Book said U.S. economic activity slowly gained strength in 2011, with manufacturers and retailers were having some success in pushing their prices up.

The market is slowly adjusting to the new environment (of high oil prices) and beginning to realize that there is no short-term solution to this, that we are going to live with this uncertainty for a some time, said Robert Lutts, chief investment officer at Cabot Money Management in Salem, Massachusetts.

Stocks have taken their cue from oil since the start of turmoil in the Middle East and northern Africa in January. Investors fear rising oil prices could derail the economic recovery. For a graph of equities' correlation to oil, see http://r.reuters.com/mut38r

The Dow Jones industrial average <.DJI> was up 21.00 points, or 0.17 percent, at 12,079.02. The Standard & Poor's 500 Index <.SPX> was up 3.30 points, or 0.25 percent, at 1,309.63. The Nasdaq Composite Index <.IXIC> was up 10.66 points, or 0.39 percent, at 2,748.07.

U.S. private sector employers added more jobs than expected last month in a sign of steady improvement in the labor market, ahead of the closely watched U.S. government's monthly non-farm payrolls report on Friday.

A broker upgrade of the semiconductor sector helped the Nasdaq. The Philadelphia semiconductor index <.SOX> rose 1.8 percent.

Texas Instruments Inc gained 3.9 percent to $36.36 after JPMorgan upgraded the semiconductor sector, including Texas Instruments, saying an inventory correction was nearing an end and demand appeared to be improving.

Apple shares boosted the Nasdaq after Chief Executive Steve Jobs surprised investors by personally presenting the new iPad at an event in San Francisco. The stock rose 0.8 percent at $351.76.

Shares in Yahoo Inc rose 3.8 percent to $16.71. The company is in advanced talks to leave its Japanese joint venture and free up as much as $8 billion to compete with Google Inc and Facebook.

(Reporting by Angela Moon, Editing by Kenneth Barry)