Thursday, March 29, 2012
Attach DB problem
I've read that it's not possible to attach DB detached from SQL2005 to
SQL2000. But by some reason I can do it with the database of one of the
client. When I try to do the same with the second client database I get an
Error 602.
What is correct - database from SQL2005 cannot be attached to SQL2000, or it
can be attached?
Why I can do it with one DB, but cannot with another one. Both DBs do not
give me any problem if I'm attaching them to SQL2005 running on my second
development machine.
Thank you
vovanMy guess is that the one that works was never attached to a SQL2005 instance
to begin with. Even if by chance it seemed to attach I would not trust it.
The system objects are no longer compatible with 2000 after it has been
attached or restored to a 2005 instance. Bottom line is that it is NOT
backward compatible.
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"vovan" <v@.v.com> wrote in message
news:uzIknmq4HHA.5984@.TK2MSFTNGP04.phx.gbl...
> I'm running SQL2000 on my development machine. 2 of our clients use
> SQL2005. I've read that it's not possible to attach DB detached from
> SQL2005 to SQL2000. But by some reason I can do it with the database of
> one of the client. When I try to do the same with the second client
> database I get an Error 602.
> What is correct - database from SQL2005 cannot be attached to SQL2000, or
> it can be attached?
> Why I can do it with one DB, but cannot with another one. Both DBs do not
> give me any problem if I'm attaching them to SQL2005 running on my second
> development machine.
> Thank you
> vovan
>|||Thank you Andrew
I was mislead by the fact that the client uses SQL 2005 Management Studio to
manage their SQL Server. But the version of SQL is 2000.
vovan
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:eDUnIYr4HHA.5316@.TK2MSFTNGP04.phx.gbl...
> My guess is that the one that works was never attached to a SQL2005
> instance to begin with. Even if by chance it seemed to attach I would not
> trust it. The system objects are no longer compatible with 2000 after it
> has been attached or restored to a 2005 instance. Bottom line is that it
> is NOT backward compatible.
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
> "vovan" <v@.v.com> wrote in message
> news:uzIknmq4HHA.5984@.TK2MSFTNGP04.phx.gbl...
>> I'm running SQL2000 on my development machine. 2 of our clients use
>> SQL2005. I've read that it's not possible to attach DB detached from
>> SQL2005 to SQL2000. But by some reason I can do it with the database of
>> one of the client. When I try to do the same with the second client
>> database I get an Error 602.
>> What is correct - database from SQL2005 cannot be attached to SQL2000, or
>> it can be attached?
>> Why I can do it with one DB, but cannot with another one. Both DBs do not
>> give me any problem if I'm attaching them to SQL2005 running on my second
>> development machine.
>> Thank you
>> vovan
>
Tuesday, March 27, 2012
Attach database to SQL2005 from old MSDE database
Then I log back into a SQL2005 database instance using the datamanager and try to attach the database. This is what their pictured instructions demonstrate. However, I get an error:
Database 'sw_charts' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.
Or... is there a way to attach the databases to SQLExpress manually?
Help pls?The instance of SQL Express needs to be run as "Local system" which is not the default. Once this is changed, the SQL Express database attaches to the old MSDE SQL 2000 database just fine, and the program appears to run without problems.
Thanks to anyone looking at my post, and hopefully, this will help others.
David|||1> use master
2> go
** close the database johandb
1>exec sp_dboption N'johandb',N'autoclose',N'false'
2>go
1>checkpoint
2>go
** detach database johan
1> exec sp_detach_db johandb, true
2> go
** attach with files
1> exec sp_attach_db @.dbname = 'johandb',
2> @.filename1='d:\mssql7\data\johandb_data.mdf',
3> @.filename2='d:\mssql7\data\johandb_log.ldf'
4> go
Regards,
Johan|||Does anyone use Lytec and SOAPware together?
MD in Texassql
Sunday, March 25, 2012
Attach an aspnet or sql2005 database on a sql2000 server
I want to attach an ASPNETDB database (generated by the asp.net login wizard system), which is a sql2005 .mdf database I think, to our SQL2000 server.
I tried to attach the file directly ; then to attach it to a sql2005 express server, "turning it" into a sql2000 database via the properties, then make a backup, then restore the backup on the 2000 server ; nothing worked out !
One of the method I tried (I don't remember which one) told me it could'nt read the sysindexes table ; of course, because there isn't such table on sql2005 databases.
So, is there a way to attach a SQL2005 database (so with no or few system tables) to a SQL2000 server (which requires those tables), or to re-generate the ASPNETDB in the SQL2000 format ?
If I re-create the syssomething tables on the SQL2005 database, will it work that simply ?
At the very last, I may have to install SQL express on the server. If there is already a SQL2000 server on the machine, will it cohabit with no problem ? Is the SQL express server ready for a production server with light or medium load ?
Thanks a lot, and sorry for so many questions ! :)
Hi,
"I want to attach an ASPNETDB database (generated by the asp.net login wizard system), which is a sql2005 .mdf database I think, to our SQL2000 server."
-That′s not working, the format is different to SQL Server 2k5, there is no backward compatibility.
""turning it" into a sql2000 database"
-Making the compatibility level to 2000 doesn't mean that the database is 2000 ready, it just behaves on a SQL2k5 machine like a SQL 2k database.
You will either have to script the object and the data out or bcp the data out or use any wizard to transfer the objects to the other SQL 2000 Server machine.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
|||Ok, and if I export the database structure as a SQL script, will it just work ?And for the SQL2005 Express server, is it usable along with the SQL2000 server, and does it fits for a ligt-load production server ?
thanks !
|||
Hi,
sure as long as you don′t use any new features of SQL Server 2005 and you take care of the difference of schema and owner you should be fine.
SQL 2k and SQL2k5X is working together. It can be also used as a light load production server (whatever that means in your case :-) ), it is only limited by the limitations of SQL Server Express, no query governor or anything else.
HTH, jens Suessmeyer.
http://www.sqlserver2005.de
Thursday, February 9, 2012
asp.net 2, sql2005, double data rows
I'm stumped. When using the classic asp page, the table produced on the web has 4 rows. But, when using the asp.net 2.0 side against the same stored proc, I get double the rows - 8. However, when I pull from the sql table directly there are only 4 rows. Any ideas? I've looked at this far too many hours...
da = New Data.SqlClient.SqlDataAdapter("pTblTempDisplayInsert2 0,'" & coList & "','" & tblList & "','" & varTblNameT & "'", cn)da.Fill(ds, "myTables")For Each drow As System.Data.DataRow In ds.Tables("myTables").Rows varTxt &= drow.Item("titleID") & "<br />"Next I get:1852
1850
2055
2053
1852
1850
2055
2053
If I run the last line of the stored procedure with the variable table name filled in:
SELECT d.titleID FROM ##varTblName d LEFT JOIN xtblTitles t ON d.tblID=t.tblID LEFT JOIN tblStatTitles s ON d.titleID=s.titleID LEFT JOIN xtblURL u ON u.urlID=t.urlID ORDER BY d.tblID, d.[year], d.lineOrder, d.countyIDI get:
1852
1850
2055
2053
If I do a simple select * from ##varTableName, I get four rows...
Thanks,
Janet
First, parameterize your query, then post if you still have an issue.
dim cmd as new sqlcommand("sp_MySP",conn)
cmd.commandtype=storedproc ' not correct property or value, but something similiar
cmd.parameters.add("coList",sqldbtype.varchar).value=colist
cmd.parameters.add ...
cmd.parameters.add ...
da=new sqldataadapter(cmd)
...
|||
Thanks SO much for replying. Okay, here you go... I'm going to show the call to the stored proc from both sides (a test aspx/aspx) the values, and the params for the aspx. Sorry it's so much, but since it works on one page and not the other, I'm obviously missing something...
test.aspx (correct-same as old asp):
<%@. Import Namespace="System.Data.SqlClient" %>
<%@. Import Namespace="System.Web.UI.WebControls" %>
<%@. Import Namespace="System.Data" %>
<%@. Page Language="VB" debug="True"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<script runat="server">
Sub Page_load(ByVal sender As Object, ByVal e As EventArgs)
Dim strConn As String = ConfigurationManager.ConnectionStrings("strConnCEguest").ConnectionString
Dim cn As New Data.SqlClient.SqlConnection(strConn)
Dim ds As New Data.DataSet
Dim da As New Data.SqlClient.SqlDataAdapter
Dim coList As String, tblList As String, varTxt As String, varTblNameT As String
tblList = "(101)"
coList = "(21)"
varTblNameT = "curly"
varTxt = "coList=" & coList & "<br />tblList=" & tblList & "<br />"da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pTblTempDisplayInsert2", cn)
da.SelectCommand.CommandType = Data.CommandType.StoredProcedure
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.year", Data.SqlDbType.Int, 1))
da.SelectCommand.Parameters("@.year").Value = 0
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.coID", Data.SqlDbType.VarChar, 100))
da.SelectCommand.Parameters("@.coID").Value = coList
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.tblID", Data.SqlDbType.VarChar, 500))
da.SelectCommand.Parameters("@.tblID").Value = tblList
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.tblName", Data.SqlDbType.VarChar, 25))
da.SelectCommand.Parameters("@.tblName").Value = varTblNameT
da.Fill(ds, "writeTables")varTxt &= "chad.dbo.pTblTempDisplayInsert2" & da.SelectCommand.Parameters("@.year").Value & "," & da.SelectCommand.Parameters("@.coID").Value & "," & da.SelectCommand.Parameters("@.tblID").Value & "," & da.SelectCommand.Parameters("@.tblName").Value & "<br />"
For Each drow As System.Data.DataRow In ds.Tables("writeTables").Rows
varTxt &= drow.Item("titleID") & "<br />"
Next
lblMsg.Text = varTxt
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
I get:
coList=(21)
tblList=(101)
chad.dbo.pTblTempDisplayInsert2 0,(21),(101),curly
1852
1850
2055
2053
select.aspx code (incorrect):
<asp:Content ID="Content2" ContentPlaceHolderID="contentHolder" Runat="Server">
<p><asp:Label ID="lblMsg" runat="server" /></p><asp:PlaceHolder ID="selectForm" runat="server"><span class="small">
<table border="0" cellpadding="5" cellspacing="0">
<tr><td colspan="2"><asp:CheckBoxList ID="chkCounty" runat="server" RepeatDirection="Vertical" RepeatColumns="3" /><td></tr>
<tr><td><asp:DropDownList ID="ddlCat" runat="server /></td>
<td><asp:RadioButtonList ID="radioSex" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" >
<asp:ListItem Value="0" Text="All genders" Selected></asp:ListItem>
<asp:ListItem Value="1" Text="Male"></asp:ListItem>
<asp:ListItem Value="2" Text="Female"></asp:ListItem>
</asp:RadioButtonList></td></tr>
<tr><td><asp:DropDownList ID="ddlSource" runat="server /></td><td><asp:DropDownList ID="ddlAge" runat="server /></td></tr>
<tr><td ><asp:TextBox runat="server" id="keywords" Columns="10 /></td>
<td><asp:RadioButtonList ID="radioRace" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" >
<asp:ListItem Value="0" Text="NA" Selected="true"></asp:ListItem>
<asp:ListItem Value="1" Text="Designated"></asp:ListItem>
</asp:RadioButtonList></td></tr>
<tr><td></td><td><asp:RadioButtonList ID="radioHisp" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" >
<asp:ListItem Value="0" Text="NA" Selected="true"></asp:ListItem>
<asp:ListItem Value="1" Text="Designated"></asp:ListItem>
</asp:RadioButtonList></td></tr>
<asp:TextBox id="txtYear" runat="server" text="0" Visible="false" />
<tr><td colspan="2"><asp:Button runat="server" ID="btnSubmit" Text="Submit" /></td></tr></table>
</asp:PlaceHolder>
<asp:PlaceHolder ID = "selectList" runat="server">
<asp:Button ID="btnSelectList" Text="Submit" OnClick="chkSelectedItems" runat="server" />
<asp:CheckBoxList ID="chkSelectList" RepeatDirection= "Vertical" runat="server" />
</asp:PlaceHolder>
</asp:Content>Partial Class chad_select
Inherits System.Web.UI.Page
Public strConn As String = ConfigurationManager.ConnectionStrings("blah").ConnectionString
Public cn As New Data.SqlClient.SqlConnection(strConn)
Public ds As New Data.DataSet
Public da As New Data.SqlClient.SqlDataAdapter
Public coList2 As StringProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
selectForm.Visible = "True"
selectList.Visible = "False"
tableDisplay.Visible = "False"
da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pCountyList 0", cn)
da.Fill(ds, "county")
chkCounty.DataSource = ds.Tables("county")
chkCounty.DataTextField = ds.Tables("county").Columns("county").ColumnName.ToString()
chkCounty.DataValueField = ds.Tables("county").Columns("countyID").ColumnName.ToString()da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pCategoriesList 0", cn)
da.Fill(ds, "category")
ddlCat.DataSource = ds.Tables("category")
ddlCat.DataTextField = ds.Tables("category").Columns("category").ColumnName.ToString()
ddlCat.DataValueField = ds.Tables("category").Columns("catID").ColumnName.ToString()da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pAgeGroupList 0", cn)
da.Fill(ds, "ages")
ddlAge.DataSource = ds.Tables("ages")
ddlAge.DataTextField = ds.Tables("ages").Columns("ageGroup").ColumnName.ToString()
ddlAge.DataValueField = ds.Tables("ages").Columns("ageID").ColumnName.ToString()
ddlAge.SelectedIndex = 0da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pSourceList 0", cn)
da.Fill(ds, "source")
ddlSource.DataSource = ds.Tables("source")
ddlSource.DataTextField = ds.Tables("source").Columns("source").ColumnName.ToString()
ddlSource.DataValueField = ds.Tables("source").Columns("sourceID").ColumnName.ToString()
ddlSource.SelectedIndex = 0
Page.DataBind()
End If
End SubProtected Sub getList(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If chkCounty.SelectedIndex = -1 Then
lblMsg.ForeColor = Drawing.Color.Crimson
lblMsg.Text = " ~ You must select at least one county."
selectForm.Visible = "True"
selectList.Visible = "False"
tableDisplay.Visible = "False"
Else
Dim varCat As Int32 = ddlCat.SelectedValue
Dim varSrc As Int32 = ddlSource.SelectedValue
Dim varAge As Int32 = ddlAge.SelectedValue
Dim varYear As Int32 = txtYear.Text
Dim varDisc As Int32 = txtDisp.Text
Dim varKey As String
If keywords.Text = "" Then varKey = "" Else varKey = keywords.TextFor Each li As ListItem In chkCounty.Items
If li.Selected Then coList2 += "," & li.Value
Next
coList2 = Right(coList2, Len(coList2) - 1)da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pMultipleCounties '" & coList2 & "'", cn)
da.Fill(ds, "county")lblMsg.ForeColor = Drawing.Color.Black
lblMsg.Text = "Your Selections: County(ies)="
Dim dr As Data.DataRow
For Each dr In ds.Tables("county").Rows
lblMsg.Text &= Trim(dr("county")) & ", "
Next
lblMsg.Text = Left(lblMsg.Text, Len(lblMsg.Text) - 2)
lblMsg.Text &= "; Category:"
If (ddlCat.SelectedIndex = -1) Or (Convert.ToInt32(ddlCat.SelectedValue) = 0) Then
lblMsg.Text &= "All"
Else
da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pCategoriesList " & varCat, cn)
da.Fill(ds, "category")
lblMsg.Text &= ds.Tables("category").Rows(0).Item("category")
End If
lblMsg.Text &= "; Age group: "
If (ddlAge.SelectedIndex = -1) Or (Convert.ToInt32(ddlAge.SelectedValue) = 0) Then
lblMsg.Text &= "All"
Else
da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pAgeGroupList " & varAge, cn)
da.Fill(ds, "ages")
lblMsg.Text &= ds.Tables("ages").Rows(0).Item("ageGroup")
End If
lblMsg.Text &= "; Source: "
If (ddlSource.SelectedIndex = -1) Or (Convert.ToInt32(ddlSource.SelectedValue) = 0) Then
lblMsg.Text &= "All"
Else
da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pSourceList " & varSrc, cn)
da.Fill(ds, "source")
lblMsg.Text &= ds.Tables("source").Rows(0).Item("Source")
End If
If Convert.ToInt32(radioRace.SelectedValue) = 0 Then
lblMsg.Text &= "; Race: All"
Else
lblMsg.Text &= "; Race: Designated"
End If
If Convert.ToInt32(radioHisp.SelectedValue) = 0 Then
lblMsg.Text &= "; Hispanic Ethnicity: All"
Else
lblMsg.Text &= "; Hispanic Ethnicity: Designated"
End If
Select Case Convert.ToInt32(radioSex.SelectedValue)
Case 0
lblMsg.Text &= "; Gender: All"
Case 1
lblMsg.Text &= "; Gender: Male"
Case 2
lblMsg.Text &= "; Gender: Female"
End Select
If varKey = "" Then
lblMsg.Text &= "; Keywords: NA"
Else
lblMsg.Text &= "; Keywords: " & varKey
End Ifda = New Data.SqlClient.SqlDataAdapter("chad.dbo.spSelectTblList " & varSrc & "," & varCat & "," & varAge & "," & Convert.ToInt32(radioSex.SelectedValue) & "," & Convert.ToInt32(radioRace.SelectedValue) & "," & Convert.ToInt32(radioHisp.SelectedValue) & ",0,'" & varKey & "','" & coList2 & "'", cn)
da.Fill(ds, "selectList")
If ds.Tables("selectList").Rows.Count > 0 Then
chkSelectList.DataSource = ds.Tables("selectList")
chkSelectList.DataTextField = "myTitle"
chkSelectList.DataValueField = "tblID"
chkSelectList.DataBind()lblMsg.Visible = "True"
selectForm.Visible = "False"
selectList.Visible = "True"
tableDisplay.Visible = "False"
Else
lblMsg.Text = "There were no items matching your selection criteria. Please try again."
lblMsg.ForeColor = Drawing.Color.Crimson
lblMsg.Visible = "True"
selectForm.Visible = "True"
selectList.Visible = "False"
tableDisplay.Visible = "False"
End If
End If
End SubProtected Sub chkSelectedItems(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSelectList.Click
If chkSelectList.SelectedIndex = -1 Then
lblMsg.ForeColor = Drawing.Color.Crimson
lblMsg.Text = " ~ You must select at least one table."
selectForm.Visible = "False"
selectList.Visible = "True"
tableDisplay.Visible = "False"
Else
Dim varTblNameT As String
varTblNameT = "harry2"
Dim varTxt As String = Nothing
Dim coList As String = Nothing
Dim tblList As String = Nothing'get tables
For Each li2 As ListItem In chkSelectList.Items
If li2.Selected = True Then
tblList &= Convert.ToString(li2.Value) & ","
End If
Next
tblList = "(" & Left(tblList, Len(tblList) - 1) & ")"'get counties
For Each li As ListItem In chkCounty.Items
If li.Selected = True Then
coList &= Convert.ToString(li.Value) & ","
End If
Next
coList = "(" & Left(coList, Len(coList) - 1) & ")"varTxt = "coList=" & coList & "<br />tblList=" & tblList & "<br />"
da = New Data.SqlClient.SqlDataAdapter("chad.dbo.pTblTempDisplayInsert2", cn)
da.SelectCommand.CommandType = Data.CommandType.StoredProcedure
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.year", Data.SqlDbType.Int, 1))
da.SelectCommand.Parameters("@.year").Value = 0
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.coID", Data.SqlDbType.VarChar, 100))
da.SelectCommand.Parameters("@.coID").Value = coList
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.tblID", Data.SqlDbType.VarChar, 500))
da.SelectCommand.Parameters("@.tblID").Value = tblList
da.SelectCommand.Parameters.Add(New Data.SqlClient.SqlParameter("@.tblName", Data.SqlDbType.VarChar, 25))
da.SelectCommand.Parameters("@.tblName").Value = varTblNameT
da.Fill(ds, "writeTables")
varTxt &= "chad.dbo.pTblTempDisplayInsert2" & da.SelectCommand.Parameters("@.year").Value & "," & da.SelectCommand.Parameters("@.coID").Value & "," & da.SelectCommand.Parameters("@.tblID").Value & "," & da.SelectCommand.Parameters("@.tblName").Value & "<br />"
For Each drow As System.Data.DataRow In ds.Tables("writeTables").Rows
varTxt &= drow.Item("titleID") & "<br />"
Next
lblMsg.Text = varTxt
lblMsg.Visible = "True"
selectForm.Visible = "False"
selectList.Visible = "False"
tableDisplay.Visible = "True"
End If
End SubEnd Class
I get:
coList=(21)
tblList=(101)
chad.dbo.pTblTempDisplayInsert2 0,(21),(101),harry2
1852
1850
2055
2053
1852
1850
2055
2053
When I do a pull from the very last execution of the stored procedure I only get 4 lines: (SELECT * FROM ##harry2 d LEFT JOIN dbo.xtblTitles t ON d.tblID=t.tblID LEFT JOIN dbo.tblStatTitles s ON d.titleID=s.titleID LEFT JOIN chad.dbo.xtblURL u ON u.urlID=t.urlID)
Thanks for anything you can point to... Janet
Two things I would try, since I'm not seeing it:
Right before your da.fill(ds,"writetables") do ds=new dataset just to make sure the dataset is empty. Then I would try running the following in query analyzer/MMS
EXEC chad.dbo.pTblTempDisplayInsert2 0,(21),(101),harry2
EXEC chad.dbo.pTblTempDisplayInsert2 0,(21),(101),harry2
And see what it returns. Does it return 8 rows in the second resultset?
And then of course, I would run Sql Profiler to see the exact commands the web application is sending and in what order, then I would copy them one by one to query analyzer and execute them and see what is getting returned. I notice you are using temporary tables in your SP's. Is it possible that the data is being added to the temporary tables without being cleared out first?
|||Well, piss-moan-complain-cheer! The ds=new dataset did the trick.
But, I don't understand it. Just to be safe, I did a search on all the code for "writeTables": the table within the dataset ds. This is the only place that it is used. So, even if the dataset is open from previous placeholder events on the page, this table within the dataset is only used for the first time with the btn click event, so why the doubling?
I'd appreciate your input, I'm new to this, obviously, and would like to try to understand it a bit more... And, I can't thank you enough for taking your time to look at this for me.
Janet