Showing posts with label deleting. Show all posts
Showing posts with label deleting. Show all posts

Monday, March 26, 2012

How to remove a database without deleting the mdf file ?

I have both sql 2005 express and developer edition installed.
If I have attached a mdf file to my local sql server default instance, how can I remove that database from this instance without deleting the underlying mdf file ? I have attached an mdf file under sql 2005 (dev edition) default instance, but now I want to detach it and reattach it under my sql 2005 express named instance. Why is there not a "detach" menu option ?

help ?for some strange reason, a "detach" menu option is there when I select the database node in the left panel of mgt studio, then right-click the db and choose tasks > detach.

Oh wait, its there under the right-click menu in the left pane as well. disregard everything i just said

How to reinitialize when "There is a problem with your selected data store"?

I've been trying to reinitialize the membership database, but something stops me.

I have tried deleting aspnetdb.mdf from the App_Data folder. This works fine, and then a new one is created when I use the asp.net adminstration tool. I can use the server explorer to view the table content (all null).

Although I can open the asp.net configuration page, the problem occurs when I select security. Then I get the error

There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem:Database 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\asp.netwebadminfiles\App_Data\ASPNETDB.MDF' already exists. Could not attach file 'C:\Documents and Settings\Jeff Leese\My Documents\world\my work\current\counsellor\App_Data\ASPNETDB.MDF' as database 'ASPNETDB_devjeffleese'.

All this seems to have happened after I modified my connection info in the web.config file:

<connectionStrings>

<removename="LocalSqlServer"/>

<addname="LocalSqlServer"connectionString="Data Source=.\SQLEXPRESS; AttachDbFilename=|DataDirectory|\ASPNETDB.MDF; user instance=true; Integrated Security=True; Initial Catalog=ASPNETDB_devjeffleese;"

providerName="System.Data.SqlClient" />

</connectionStrings>

So, two questions:

1) What are the sections about? They seem to have been inserted automatically at some point, and I wonder if its just formatting info or should I remove them?

2) How can I get security going again. How do I deal with the 'already exists' problem that prevents 'attaching' ?

Would greatly appreciate guidance in how to start over...

Hi,

I had a similar problem with the install of the ASPNET DB, and I'll try to recall how I got it running.

What I tried first was to hae the DB istalled automatically from the WS I have running VS 2005, which is networked to a server running SQL Server 2005 (Standard). I wanted the DB installed on that SQL Server instance, but ran into problem. Even pre-creating the DB ther didn't seem to help. I'm not saying it can't be done, but it wasn't worth the effort to me. I DL'ed and installed an instance of SQL Server Express on the WS that has VS, did the aspnet_regsql.exe, and things worked Ok. I figure I can transfer the DB to the full SQL Server when/if I need to, but where it is is fine for development work. (Side note: I installed the Full version client tools on the WS, so I'd have these, rather than the Expess manager - but getting the uninstall/install sequence right was a hassle).

I didn't see a mention of aspnet_regsql.exe in your post. If you havent used it, do a search on msdn.microsoft.com for how and why to use it. You should find it in your Windows\Microsoft.net\Framework\(the version you are running). You should find it there, in the same place as the reg for IIS (if you need that too).

Good luck, hop eit helps. BRN..

Friday, March 23, 2012

How to reflect base table changes in cursor

I have a small question -

I have a cursor which is running on the table and i am deleting some rows from the same table during the cursor loop but it didnt reflecting it. Is there is any other option i need to sepcify during declare.

declare localshowcursor cursor for
SELECT video_release, programname, network, date_encoded, time_encoded, COUNT(*) AS Number
FROM SigmaStageTemp s
Where program_type = ‘1’
Group by video_release, programname, network, date_encoded, time_encoded
Having count(*) >= 10
Order by video_release, programname, network, date_encoded, time_encoded

Please help

Ashish,

Most likely, you don't need to be using a CURSOR.

Please post the code that executes for the CURSOR position, and perhaps we can help you do the same task in a SET based operation -which will be faster and less disruptive than using a CURSOR.

|||

Below is my complete code. It select the range of records from the base table and insert into a different table and then deletes those records from the base table but when i debuged the cursor i am still getting the value of time_encoede which should be deleted.

declare @.pgname nvarchar(20)
declare @.videorelease nvarchar(40)
declare @.dateaired nvarchar(15)
declare @.dateencoded nvarchar(15)
declare @.timeencoded nvarchar(15)
declare @.network nvarchar(12)
declare @.count int

declare localshowcursor cursor for
SELECT video_release, programname, network, date_encoded, time_encoded, COUNT(*) AS Number
FROM SigmaStageTemp s
Where program_type = ‘1’
Group by video_release, programname, network, date_encoded, time_encoded
Having count(*) >= 10
Order by video_release, programname, network, date_encoded, time_encoded

OPEN localshowcursor

FETCH NEXT FROM localshowcursor INTO @.videorelease, @.pgname, @.network, @.dateencoded, @.timeencoded, @.count

WHILE @.@.FETCH_STATUS = 0
BEGIN

Insert into sigmtemp(Video_release, country, market_rank, Designated_mrkt_area, station, network, date_aired, day_of_week, day_part, half_hour_aired, programname, program_type, start_time, end_time, length_aired, date_encoded, time_encoded, rel_type, VR_CODE1, VR_CODE2, VR_CODE3, VR_CODE4, DMA_CODE, sid_code, station_code)
(Select top(1)
Video_release, country, market_rank, Designated_mrkt_area, station, network, date_aired, day_of_week, day_part, half_hour_aired, programname, program_type, start_time, end_time, length_aired, date_encoded, time_encoded, rel_type, VR_CODE1, VR_CODE2, VR_CODE3, VR_CODE4, DMA_CODE, sid_code, station_code

from sigmastagetemp s1
where s1.video_release = @.videorelease and
s1.programname = @.pgname and
s1.network = @.network and
s1.date_encoded = @.dateencoded and
convert(int,s1.time_encoded) between convert(int,@.timeencoded) -2 and
convert(int,@.timeencoded) +2

Order by video_release, programname, network, date_encoded, time_encoded )

Delete
from sigmastagetemp
where video_release = @.videorelease and
programname = @.pgname and
network = @.network and
date_encoded = @.dateencoded and
convert(int,time_encoded) between convert(int,@.timeencoded) -2 and
convert(int,@.timeencoded) +2

FETCH NEXT FROM localshowcursor INTO @.videorelease, @.pgname, @.network, @.dateencoded, @.timeencoded, @.count
END

CLOSE localshowcursor
DEALLOCATE localshowcursor

|||

You can't achive it on the cursor.

When you use the GROUP BY, all the result will be stored in the temp table and the temp table will be served for your cursor.

The only communication with your table is on the DECLARE & OPEN cursor. After that it will be acted independetly....

The Following query proves this,

Code Snippet

Create table TESTCUR

(

Num Int,

Chr Char

)

Insert Into TESTCUR VALUES(1,'A')

Insert Into TESTCUR VALUES(1,'A')

Insert Into TESTCUR VALUES(1,'A')

Insert Into TESTCUR VALUES(1,'B')

Insert Into TESTCUR VALUES(1,'B')

Insert Into TESTCUR VALUES(1,'B')

Insert Into TESTCUR VALUES(1,'C')

Insert Into TESTCUR VALUES(1,'C')

Insert Into TESTCUR VALUES(1,'D')

Go

Declare TESTCURFUN Cursor DYNAMIC

For Select Count(NUM) C,Chr From TESTCUR Group BY Chr;

Declare @.I as int, @.N Char;

Open TESTCURFUN

Fetch TESTCURFUN INTO @.I,@.N

--Drop the Table

Drop Table TESTCUR

While @.@.FETCH_STATUS = 0

Begin

Select @.I,@.N

Fetch TESTCURFUN INTO @.I,@.N

End

Close TESTCURFUN

DEALLOCATE TESTCURFUN

--Try the same logic without group by you might get error.

sql