Showing posts with label method. Show all posts
Showing posts with label method. Show all posts

Thursday, March 29, 2012

Determine the size of an Image datatype

Is there any method to find out the size of an image datatype currently in the database. For example I have 2 tables that contain the same image, but the archive table is not displaying the same as the main. I am thinking the image file was corrupted somehow but don't know how to check this out.
Any ideas?DataLength() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_da-db_4ep4.asp)

-PatP

Tuesday, March 27, 2012

Determine Next Available Order ID

I am trying to determine the next available order id using the method below. It works provided the table has a record in it. If it doesn't I get the error "Input string was not in a correct format." I am certain that it is because the query is returning a value of NULL. How can get around that or check for the NULL value?

' Establish data connection...

Dim sqlConnAsNew SqlConnection(ConfigurationSettings.AppSettings("connectionstring"))

'Determine order id number...

Dim order_idAsInteger

Dim strSQLAsString

strSQL = "Select MAX(order_id) from mkt_order"

Dim sqlCmdAsNew SqlCommand(strSQL, sqlConn)

Dim sqlDAAsNew SqlDataAdapter(sqlCmd)

Dim sqlDSAsNew DataSet

sqlDA.Fill(sqlDS, "item")

If sqlDS.Tables(0).Rows.Count <> 0Then

order_id = Convert.ToInt32(sqlDS.Tables(0).Rows(0)(0).ToString()) + 1

Else

order_id = 1

EndIf

This is because a DBNull will be returned if you use MAX() function and there is no (qualified) record in the table. Let's try TOP...ORDER BY... to avoid using MAX():

strSQL = "Select TOP 1 order_id from mkt_order ORDER BY order_id DESC"

Thursday, March 22, 2012

Determine #transaction per second per db

Whats the best method of determining #trans per sec per db in a SQL2000 Enterprise sp3? Thx in adv.Depends on your view of what a transaction is but how about monitoring the
Transactions/Sec counter in Perfmon under SQL Databases.
--
Andrew J. Kelly SQL MVP
"LIZ" <anonymous@.discussions.microsoft.com> wrote in message
news:2C79D01A-6D04-4D5F-8FE5-2A6C0E1795DA@.microsoft.com...
> Whats the best method of determining #trans per sec per db in a SQL2000
Enterprise sp3? Thx in adv.|||You could also use the transactions even in SQL Profiler, which also
captures the database... You could save the trace into a SQL table and do a
query grouped by database
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"LIZ" <anonymous@.discussions.microsoft.com> wrote in message
news:2C79D01A-6D04-4D5F-8FE5-2A6C0E1795DA@.microsoft.com...
> Whats the best method of determining #trans per sec per db in a SQL2000
Enterprise sp3? Thx in adv.sql

Detecting the render method using an expression

Is there a way of detecting (in an expression in the report) the render
method that is being used to render the report?
Scenario
I have created a custom assembly that sits in the footer of a report and
writes the total number of pages to a database table. However, the total
number of pages varies depending on the render method used, and I need to
capture this render method along with the total pages.
I can't pass the render method into the report as a parameter because, even
when rendering with a single render format such as PDF the report seems to
render twice:
string format = "PDF";
results = viewer.ServerReport.Render(format, deviceInfo, out mimeType, out
encoding, out fileNameExtension, out streamIDs, out warnings);
The above code inserts two records into the database table (once as either
XML or HTML and then as PDF). The first record reflects the total pages
displayed in the viewer, and the second record reflects totalPages as if
exported into PDF.
If we could detect which format was being used at render time then we could
get around this double rendering problem.Hello Stu,
I undertstand that you want to pass the render type in the expression.
Well you could not pass the render type in the expression.
Could you please let me know how your custom code to insert the total page
information?
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi Wei Lu,
The expression in the report is:
--
="Page "&Globals!PageNumber & " of "
&LogAttributes.CommonFunctions.LogReportDetails(Globals!ReportName,
Globals!TotalPages, Globals!PageNumber, Parameters!SnapshotID.Value,
Parameters!SchemaName.Value,
Parameters!Database.Value,Parameters!UserID.Value,Parameters!Password.Value,
Parameters!Server.Value)
--
And the code in the custom assembly is:
--
public static int LogReportDetails(string reportName, int
totalNumberOfPages, int currentPage, int snapShotID, string schema,
string database, string userID, string password, string server)
{
bool testRun = false;
if (currentPage == totalNumberOfPages) { testRun = true; } else
{ testRun = false; }
if (testRun)
{
int totalNumPages;
bool ok = true;
TableOfContents toc = new TableOfContents();
toc.Description = reportName;
toc.TotalNumberOfPages = totalNumberOfPages;
toc.CurrentPage = currentPage;
toc.SnapshotID = snapShotID;
toc.SchemaName = schema;
toc.Database = database;
toc.UserID = userID;
toc.Password = password;
toc.Server = server;
SqlTOCDalc dalc = new SqlTOCDalc();
totalNumPages = dalc.InsertTocRow(toc, ok);
return totalNumPages;
}
else
{
return totalNumberOfPages;
}
}
--
Thanks
Stu
"Wei Lu [MSFT]" wrote:
> Hello Stu,
> I undertstand that you want to pass the render type in the expression.
> Well you could not pass the render type in the expression.
> Could you please let me know how your custom code to insert the total page
> information?
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||Hello Stu,
Well, unfortunately, you could not refer the render method in the custom
code. And the only workaround I thought is that you may need to add the
custom application to call the report instead of the access the report via
the web browser.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.

Wednesday, March 21, 2012

Detect whether runtime or executiontime in custom component

In my custom component in the validate() method I want to determine whether this method is called during runtime or during designtime. I Can't find a property for this on PipelineComponent or ComponentMetaData. Is it possible?

Regards,
HenkI don't think you can, and I also don't think it should matter. Why would you want this?|||Well, during validation I want to access a package level variable that is filled with a lookup table by a preceding task. However, at designtime, there is no such thing as a task that has executed previously, so the variable does not exist then.
|||Should the variable not exist, but the value may be rubbish? You cannot create variables at run-time (... I'm pretty sure you can't, no run-time structure changes allowed in SSIS). If something is really missing I think you are perhaps digging too deep into the validation, unless it is only certain settings that induce this issue.

The way to get round this would be to set DelayValidation to true, so validation only happens at runtime.

You would do this for a Exec SQL Task that requires a table for created by a preceeding task, such that the table will not exist until part through run-time. Normally it is good to validate the SQL, but in this case it will cause a problem, so we can bypass validation.|||

DarrenSQLIS wrote:

You cannot create variables at run-time

I'm afraid I didn't make myself clear. I do not create variables at runtime.

But is my observation correct that if you define a variable (at designtime of course!) at package level, that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime? (so it doesn't even contain rubbish, but it just isn't there)

(By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)|||

Henk v J. wrote:

that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime


You sure? I have a component that uses variables, actually the variable name is a property value, and I validate that the variable selected does exist. This works at design-time calls to Validate.

Henk v J. wrote:

By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)


Don't be shy. I'm intrigued now, what have you done?

|||No rocket-science, I just look whether the variable exists and if it doesn't I do nothing Big Smile

By the way you are probably right about, because I can't see the variable at runtime either, so there is something else wrong... I post a separate issue on that.
Thanks for your reactions!|||Ok, I lied I don't use variables in Validate, but I do in AcquireConnections, so still in a component, and that is called during design and execution times.



if (VariableDispenser.Contains(location))
{
IDTSVariables90 vars = null;
VariableDispenser.LockOneForRead(location, ref vars);
return vars[0].Value.ToString();
}

|||Try me.Designmode property may be it will work for you.

Detect whether runtime or designtime in custom component

In my custom component in the validate() method I want to determine whether this method is called during runtime or during designtime. I Can't find a property for this on PipelineComponent or ComponentMetaData. Is it possible?

Regards,
HenkI don't think you can, and I also don't think it should matter. Why would you want this?|||Well, during validation I want to access a package level variable that is filled with a lookup table by a preceding task. However, at designtime, there is no such thing as a task that has executed previously, so the variable does not exist then.
|||Should the variable not exist, but the value may be rubbish? You cannot create variables at run-time (... I'm pretty sure you can't, no run-time structure changes allowed in SSIS). If something is really missing I think you are perhaps digging too deep into the validation, unless it is only certain settings that induce this issue.

The way to get round this would be to set DelayValidation to true, so validation only happens at runtime.

You would do this for a Exec SQL Task that requires a table for created by a preceeding task, such that the table will not exist until part through run-time. Normally it is good to validate the SQL, but in this case it will cause a problem, so we can bypass validation.|||

DarrenSQLIS wrote:

You cannot create variables at run-time

I'm afraid I didn't make myself clear. I do not create variables at runtime.

But is my observation correct that if you define a variable (at designtime of course!) at package level, that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime? (so it doesn't even contain rubbish, but it just isn't there)

(By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)|||

Henk v J. wrote:

that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime


You sure? I have a component that uses variables, actually the variable name is a property value, and I validate that the variable selected does exist. This works at design-time calls to Validate.

Henk v J. wrote:

By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)


Don't be shy. I'm intrigued now, what have you done?

|||No rocket-science, I just look whether the variable exists and if it doesn't I do nothing Big Smile

By the way you are probably right about, because I can't see the variable at runtime either, so there is something else wrong... I post a separate issue on that.
Thanks for your reactions!|||Ok, I lied I don't use variables in Validate, but I do in AcquireConnections, so still in a component, and that is called during design and execution times.



if (VariableDispenser.Contains(location))
{
IDTSVariables90 vars = null;
VariableDispenser.LockOneForRead(location, ref vars);
return vars[0].Value.ToString();
}

|||Try me.Designmode property may be it will work for you.

Detect whether executiontime or designtime in custom component

In my custom component in the validate() method I want to determine whether this method is called during runtime or during designtime. I Can't find a property for this on PipelineComponent or ComponentMetaData. Is it possible?

Regards,
HenkI don't think you can, and I also don't think it should matter. Why would you want this?

|||Well, during validation I want to access a package level variable that is filled with a lookup table by a preceding task. However, at designtime, there is no such thing as a task that has executed previously, so the variable does not exist then.|||Should the variable not exist, but the value may be rubbish? You cannot create variables at run-time (... I'm pretty sure you can't, no run-time structure changes allowed in SSIS). If something is really missing I think you are perhaps digging too deep into the validation, unless it is only certain settings that induce this issue.

The way to get round this would be to set DelayValidation to true, so validation only happens at runtime.

You would do this for a Exec SQL Task that requires a table for created by a preceeding task, such that the table will not exist until part through run-time. Normally it is good to validate the SQL, but in this case it will cause a problem, so we can bypass validation.|||

DarrenSQLIS wrote:

You cannot create variables at run-time

I'm afraid I didn't make myself clear. I do not create variables at runtime.

But is my observation correct that if you define a variable (at designtime of course!) at package level, that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime? (so it doesn't even contain rubbish, but it just isn't there)

(By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)|||

Henk v J. wrote:

that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime


You sure? I have a component that uses variables, actually the variable name is a property value, and I validate that the variable selected does exist. This works at design-time calls to Validate.

Henk v J. wrote:

By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)


Don't be shy. I'm intrigued now, what have you done?

|||No rocket-science, I just look whether the variable exists and if it doesn't I do nothing Big Smile

By the way you are probably right about, because I can't see the variable at runtime either, so there is something else wrong... I post a separate issue on that.
Thanks for your reactions!|||Ok, I lied I don't use variables in Validate, but I do in AcquireConnections, so still in a component, and that is called during design and execution times.



if (VariableDispenser.Contains(location))
{
IDTSVariables90 vars = null;
VariableDispenser.LockOneForRead(location, ref vars);
return vars[0].Value.ToString();
}

|||Try me.Designmode property may be it will work for you.

Detect whether executiontime or designtime in custom component

In my custom component in the validate() method I want to determine whether this method is called during runtime or during designtime. I Can't find a property for this on PipelineComponent or ComponentMetaData. Is it possible?

Regards,
HenkI don't think you can, and I also don't think it should matter. Why would you want this?|||Well, during validation I want to access a package level variable that is filled with a lookup table by a preceding task. However, at designtime, there is no such thing as a task that has executed previously, so the variable does not exist then.
|||Should the variable not exist, but the value may be rubbish? You cannot create variables at run-time (... I'm pretty sure you can't, no run-time structure changes allowed in SSIS). If something is really missing I think you are perhaps digging too deep into the validation, unless it is only certain settings that induce this issue.

The way to get round this would be to set DelayValidation to true, so validation only happens at runtime.

You would do this for a Exec SQL Task that requires a table for created by a preceeding task, such that the table will not exist until part through run-time. Normally it is good to validate the SQL, but in this case it will cause a problem, so we can bypass validation.|||

DarrenSQLIS wrote:

You cannot create variables at run-time

I'm afraid I didn't make myself clear. I do not create variables at runtime.

But is my observation correct that if you define a variable (at designtime of course!) at package level, that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime? (so it doesn't even contain rubbish, but it just isn't there)

(By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)|||

Henk v J. wrote:

that variable is not seen by custom components in a dataflow task in that packge until executiontime\runtime


You sure? I have a component that uses variables, actually the variable name is a property value, and I validate that the variable selected does exist. This works at design-time calls to Validate.

Henk v J. wrote:

By the way I can easily get around the fact that I can't detect designtime or executiontime, so that's no issue anymore)


Don't be shy. I'm intrigued now, what have you done?

|||No rocket-science, I just look whether the variable exists and if it doesn't I do nothing Big Smile

By the way you are probably right about, because I can't see the variable at runtime either, so there is something else wrong... I post a separate issue on that.
Thanks for your reactions!|||Ok, I lied I don't use variables in Validate, but I do in AcquireConnections, so still in a component, and that is called during design and execution times.



if (VariableDispenser.Contains(location))
{
IDTSVariables90 vars = null;
VariableDispenser.LockOneForRead(location, ref vars);
return vars[0].Value.ToString();
}

|||Try me.Designmode property may be it will work for you.

Monday, March 19, 2012

Detailed information in aggregate report

Forgive me for asking, but I've looked around and couldnt
quite find the best method of achieving the following.
I've got a report that aggregates all sortsa data with
group by and sums and counts etc.
What I'd like to do, is if a parameter is set, use same
columns etc, but bring up details on a particular
subscriber. (one row per subscriber)
Which would require one more column for subscriber name
etc. But can I easily turn off the aggregation stuff in
the query itself?Weston,
Have you taken a look at the Microsoft SQL Server Report Pack for
Financial Reports (free download). In particular the report
"IncomeStmtCurYTD-Region" may be the effect you're looking for with the
"show all" parameter? The "Territory Sales Drilldown" included in the
Sample Reports provides the ability to "drill" into the detail.
Regards,
Paul

Friday, March 9, 2012

detach/attach loses permissions

Hi, I was wondering if anyone had insight on this. I have traditionally
always used detach/attach as a method of copying databases i.e.:
I have 2 servers running SQL 2000: serverA, serverB
My intention is to copy a database (call it DB1) from server1 to server2
I perform the following:
1. i detach DB1
2. copy it (call it DB2)
3. attach DB1 to Server1 and DB2 to server2
4. place both server1 and server2 in single user mode via the -T3608
parameter
5. detach model THEN msdb from Server1, copy them and move the copies to
server2
6. attach model THEN msdb to server1 and server2
7. remove the -T3608 parameter and restart both sql services
8. script out the logins on server1 and apply them to server2
Now that is all fine according to microsofts article:
http://support.microsoft.com/default...b;en-us;224071
However what i have noticed at times is that on server2, the logins are
missing permissions to DB2. Why does this happen?
Can things go missing if i perform it in this order:
1. place both server1 and server2 in single user mode via the -T3608
parameter
2. detach model THEN msdb from Server1, copy them and move the copies to
server2
3. attach model THEN msdb to server1 and server2
4. remove the -T3608 parameter and restart both sql services
5. i detach DB1
6. copy it (call it DB2)
7. attach DB1 to Server1 and DB2 to server2
8. script out the logins on server1 and apply them to server2
?
Missing permissions occured when i did the above for our greatplains
database.
Any help appreciated.
Cheers, john
SQL Server Logins are mapped to DB Users via an ID that can be different on
both servers, especially when they are not recreated in the exact order on
both servers. You need to use sp_change_users_login to fix the mapping
after the attach and after you recreate the logins. These links might be of
help:
http://vyaskn.tripod.com/moving_sql_server.htm Moving DBs
http://www.databasejournal.com/featu...le.php/3379901 Moving
system DB's
http://www.support.microsoft.com/?id=314546 Moving DB's between Servers
http://www.support.microsoft.com/?id=224071 Moving SQL Server Databases
to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465 Using WITH MOVE in a
Restore
http://www.sqlservercentral.com/colu...rdatabases.asp
Moving Users
http://www.support.microsoft.com/?id=246133 How To Transfer Logins and
Passwords Between SQL Servers
http://www.support.microsoft.com/?id=298897 Mapping Logins & SIDs after a
Restore
http://www.dbmaint.com/SyncSqlLogins.asp Utility to map logins to
users
http://www.support.microsoft.com/?id=168001 User Logon and/or Permission
Errors After Restoring Dump
http://www.support.microsoft.com/?id=240872 How to Resolve Permission
Issues When a Database Is Moved Between SQL Servers
http://www.sqlservercentral.com/scri...p?scriptid=599
Restoring a .mdf
http://www.support.microsoft.com/?id=307775 Disaster Recovery Articles
for SQL Server
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:%23JAspriBGHA.3896@.TK2MSFTNGP09.phx.gbl...
> Hi, I was wondering if anyone had insight on this. I have traditionally
> always used detach/attach as a method of copying databases i.e.:
> I have 2 servers running SQL 2000: serverA, serverB
> My intention is to copy a database (call it DB1) from server1 to server2
> I perform the following:
> 1. i detach DB1
> 2. copy it (call it DB2)
> 3. attach DB1 to Server1 and DB2 to server2
> 4. place both server1 and server2 in single user mode via the -T3608
> parameter
> 5. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 6. attach model THEN msdb to server1 and server2
> 7. remove the -T3608 parameter and restart both sql services
> 8. script out the logins on server1 and apply them to server2
> Now that is all fine according to microsofts article:
> http://support.microsoft.com/default...b;en-us;224071
> However what i have noticed at times is that on server2, the logins are
> missing permissions to DB2. Why does this happen?
> Can things go missing if i perform it in this order:
> 1. place both server1 and server2 in single user mode via the -T3608
> parameter
> 2. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 3. attach model THEN msdb to server1 and server2
> 4. remove the -T3608 parameter and restart both sql services
> 5. i detach DB1
> 6. copy it (call it DB2)
> 7. attach DB1 to Server1 and DB2 to server2
> 8. script out the logins on server1 and apply them to server2
> ?
> Missing permissions occured when i did the above for our greatplains
> database.
> Any help appreciated.
> Cheers, john
>
|||Logins are in master table and you dont have copied it to other server
Use sp_help_revlogin by microsoft to transfer login
http://support.microsoft.com/default.aspx?kbid=246133
OR
If login already exists on Server 2 then you need to map user to logins
in the DB2., since the SIDs are different on both the servers for the
login.
Regards
Amish
|||thanks for the help Andrew and Amish.
I have always used the following article as my approach to scripting out the
logins:
http://www.support.microsoft.com/?id=246133
This has worked in the past.
The strange thing (i.e. when this was performed on the Greatplains database)
was that when i reattached all the databases back onto Server1 (and of
course the copies on server2), permissions went missing on server1 as well.
Is this particular to greatplains?
any help appreciated.
cheers, john
"amish" <shahamishm@.gmail.com> wrote in message
news:1135174050.693957.5380@.g14g2000cwa.googlegrou ps.com...
> Logins are in master table and you dont have copied it to other server
> Use sp_help_revlogin by microsoft to transfer login
> http://support.microsoft.com/default.aspx?kbid=246133
> OR
> If login already exists on Server 2 then you need to map user to logins
> in the DB2., since the SIDs are different on both the servers for the
> login.
> Regards
> Amish
>
|||I am not quite sure what you did but have you tried the
sp_change_users_login to see if that helps?
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:ujPILOkBGHA.3840@.TK2MSFTNGP15.phx.gbl...
> thanks for the help Andrew and Amish.
> I have always used the following article as my approach to scripting out
> the logins:
> http://www.support.microsoft.com/?id=246133
> This has worked in the past.
> The strange thing (i.e. when this was performed on the Greatplains
> database) was that when i reattached all the databases back onto Server1
> (and of course the copies on server2), permissions went missing on server1
> as well.
> Is this particular to greatplains?
> any help appreciated.
> cheers, john
> "amish" <shahamishm@.gmail.com> wrote in message
> news:1135174050.693957.5380@.g14g2000cwa.googlegrou ps.com...
>

detach/attach loses permissions

Hi, I was wondering if anyone had insight on this. I have traditionally
always used detach/attach as a method of copying databases i.e.:
I have 2 servers running SQL 2000: serverA, serverB
My intention is to copy a database (call it DB1) from server1 to server2
I perform the following:
1. i detach DB1
2. copy it (call it DB2)
3. attach DB1 to Server1 and DB2 to server2
4. place both server1 and server2 in single user mode via the -T3608
parameter
5. detach model THEN msdb from Server1, copy them and move the copies to
server2
6. attach model THEN msdb to server1 and server2
7. remove the -T3608 parameter and restart both sql services
8. script out the logins on server1 and apply them to server2
Now that is all fine according to microsofts article:
http://support.microsoft.com/default.aspx?scid=kb;en-us;224071
However what i have noticed at times is that on server2, the logins are
missing permissions to DB2. Why does this happen?
Can things go missing if i perform it in this order:
1. place both server1 and server2 in single user mode via the -T3608
parameter
2. detach model THEN msdb from Server1, copy them and move the copies to
server2
3. attach model THEN msdb to server1 and server2
4. remove the -T3608 parameter and restart both sql services
5. i detach DB1
6. copy it (call it DB2)
7. attach DB1 to Server1 and DB2 to server2
8. script out the logins on server1 and apply them to server2
?
Missing permissions occured when i did the above for our greatplains
database.
Any help appreciated.
Cheers, johnSQL Server Logins are mapped to DB Users via an ID that can be different on
both servers, especially when they are not recreated in the exact order on
both servers. You need to use sp_change_users_login to fix the mapping
after the attach and after you recreate the logins. These links might be of
help:
http://vyaskn.tripod.com/moving_sql_server.htm Moving DBs
http://www.databasejournal.com/features/mssql/article.php/3379901 Moving
system DB's
http://www.support.microsoft.com/?id=314546 Moving DB's between Servers
http://www.support.microsoft.com/?id=224071 Moving SQL Server Databases
to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465 Using WITH MOVE in a
Restore
http://www.sqlservercentral.com/columnists/cBunch/movingyouruserswiththeirdatabases.asp
Moving Users
http://www.support.microsoft.com/?id=246133 How To Transfer Logins and
Passwords Between SQL Servers
http://www.support.microsoft.com/?id=298897 Mapping Logins & SIDs after a
Restore
http://www.dbmaint.com/SyncSqlLogins.asp Utility to map logins to
users
http://www.support.microsoft.com/?id=168001 User Logon and/or Permission
Errors After Restoring Dump
http://www.support.microsoft.com/?id=240872 How to Resolve Permission
Issues When a Database Is Moved Between SQL Servers
http://www.sqlservercentral.com/scripts/scriptdetails.asp?scriptid=599
Restoring a .mdf
http://www.support.microsoft.com/?id=307775 Disaster Recovery Articles
for SQL Server
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:%23JAspriBGHA.3896@.TK2MSFTNGP09.phx.gbl...
> Hi, I was wondering if anyone had insight on this. I have traditionally
> always used detach/attach as a method of copying databases i.e.:
> I have 2 servers running SQL 2000: serverA, serverB
> My intention is to copy a database (call it DB1) from server1 to server2
> I perform the following:
> 1. i detach DB1
> 2. copy it (call it DB2)
> 3. attach DB1 to Server1 and DB2 to server2
> 4. place both server1 and server2 in single user mode via the -T3608
> parameter
> 5. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 6. attach model THEN msdb to server1 and server2
> 7. remove the -T3608 parameter and restart both sql services
> 8. script out the logins on server1 and apply them to server2
> Now that is all fine according to microsofts article:
> http://support.microsoft.com/default.aspx?scid=kb;en-us;224071
> However what i have noticed at times is that on server2, the logins are
> missing permissions to DB2. Why does this happen?
> Can things go missing if i perform it in this order:
> 1. place both server1 and server2 in single user mode via the -T3608
> parameter
> 2. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 3. attach model THEN msdb to server1 and server2
> 4. remove the -T3608 parameter and restart both sql services
> 5. i detach DB1
> 6. copy it (call it DB2)
> 7. attach DB1 to Server1 and DB2 to server2
> 8. script out the logins on server1 and apply them to server2
> ?
> Missing permissions occured when i did the above for our greatplains
> database.
> Any help appreciated.
> Cheers, john
>|||Logins are in master table and you dont have copied it to other server
Use sp_help_revlogin by microsoft to transfer login
http://support.microsoft.com/default.aspx?kbid=246133
OR
If login already exists on Server 2 then you need to map user to logins
in the DB2., since the SIDs are different on both the servers for the
login.
Regards
Amish|||thanks for the help Andrew and Amish.
I have always used the following article as my approach to scripting out the
logins:
http://www.support.microsoft.com/?id=246133
This has worked in the past.
The strange thing (i.e. when this was performed on the Greatplains database)
was that when i reattached all the databases back onto Server1 (and of
course the copies on server2), permissions went missing on server1 as well.
Is this particular to greatplains?
any help appreciated.
cheers, john
"amish" <shahamishm@.gmail.com> wrote in message
news:1135174050.693957.5380@.g14g2000cwa.googlegroups.com...
> Logins are in master table and you dont have copied it to other server
> Use sp_help_revlogin by microsoft to transfer login
> http://support.microsoft.com/default.aspx?kbid=246133
> OR
> If login already exists on Server 2 then you need to map user to logins
> in the DB2., since the SIDs are different on both the servers for the
> login.
> Regards
> Amish
>|||I am not quite sure what you did but have you tried the
sp_change_users_login to see if that helps?
--
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:ujPILOkBGHA.3840@.TK2MSFTNGP15.phx.gbl...
> thanks for the help Andrew and Amish.
> I have always used the following article as my approach to scripting out
> the logins:
> http://www.support.microsoft.com/?id=246133
> This has worked in the past.
> The strange thing (i.e. when this was performed on the Greatplains
> database) was that when i reattached all the databases back onto Server1
> (and of course the copies on server2), permissions went missing on server1
> as well.
> Is this particular to greatplains?
> any help appreciated.
> cheers, john
> "amish" <shahamishm@.gmail.com> wrote in message
> news:1135174050.693957.5380@.g14g2000cwa.googlegroups.com...
>> Logins are in master table and you dont have copied it to other server
>> Use sp_help_revlogin by microsoft to transfer login
>> http://support.microsoft.com/default.aspx?kbid=246133
>> OR
>> If login already exists on Server 2 then you need to map user to logins
>> in the DB2., since the SIDs are different on both the servers for the
>> login.
>> Regards
>> Amish
>

detach/attach loses permissions

Hi, I was wondering if anyone had insight on this. I have traditionally
always used detach/attach as a method of copying databases i.e.:
I have 2 servers running SQL 2000: serverA, serverB
My intention is to copy a database (call it DB1) from server1 to server2
I perform the following:
1. i detach DB1
2. copy it (call it DB2)
3. attach DB1 to Server1 and DB2 to server2
4. place both server1 and server2 in single user mode via the -T3608
parameter
5. detach model THEN msdb from Server1, copy them and move the copies to
server2
6. attach model THEN msdb to server1 and server2
7. remove the -T3608 parameter and restart both sql services
8. script out the logins on server1 and apply them to server2
Now that is all fine according to microsofts article:
http://support.microsoft.com/defaul...kb;en-us;224071
However what i have noticed at times is that on server2, the logins are
missing permissions to DB2. Why does this happen?
Can things go missing if i perform it in this order:
1. place both server1 and server2 in single user mode via the -T3608
parameter
2. detach model THEN msdb from Server1, copy them and move the copies to
server2
3. attach model THEN msdb to server1 and server2
4. remove the -T3608 parameter and restart both sql services
5. i detach DB1
6. copy it (call it DB2)
7. attach DB1 to Server1 and DB2 to server2
8. script out the logins on server1 and apply them to server2
?
Missing permissions occured when i did the above for our greatplains
database.
Any help appreciated.
Cheers, johnSQL Server Logins are mapped to DB Users via an ID that can be different on
both servers, especially when they are not recreated in the exact order on
both servers. You need to use sp_change_users_login to fix the mapping
after the attach and after you recreate the logins. These links might be of
help:
http://vyaskn.tripod.com/moving_sql_server.htm Moving DBs
http://www.databasejournal.com/feat...cle.php/3379901 Moving
system DB's
http://www.support.microsoft.com/?id=314546 Moving DB's between Servers
http://www.support.microsoft.com/?id=224071 Moving SQL Server Databases
to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465 Using WITH MOVE in a
Restore
http://www.sqlservercentral.com/col...se
s.asp
Moving Users
http://www.support.microsoft.com/?id=246133 How To Transfer Logins and
Passwords Between SQL Servers
http://www.support.microsoft.com/?id=298897 Mapping Logins & SIDs after a
Restore
http://www.dbmaint.com/SyncSqlLogins.asp Utility to map logins to
users
http://www.support.microsoft.com/?id=168001 User Logon and/or Permission
Errors After Restoring Dump
http://www.support.microsoft.com/?id=240872 How to Resolve Permission
Issues When a Database Is Moved Between SQL Servers
http://www.sqlservercentral.com/scr...sp?scriptid=599
Restoring a .mdf
http://www.support.microsoft.com/?id=307775 Disaster Recovery Articles
for SQL Server
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:%23JAspriBGHA.3896@.TK2MSFTNGP09.phx.gbl...
> Hi, I was wondering if anyone had insight on this. I have traditionally
> always used detach/attach as a method of copying databases i.e.:
> I have 2 servers running SQL 2000: serverA, serverB
> My intention is to copy a database (call it DB1) from server1 to server2
> I perform the following:
> 1. i detach DB1
> 2. copy it (call it DB2)
> 3. attach DB1 to Server1 and DB2 to server2
> 4. place both server1 and server2 in single user mode via the -T3608
> parameter
> 5. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 6. attach model THEN msdb to server1 and server2
> 7. remove the -T3608 parameter and restart both sql services
> 8. script out the logins on server1 and apply them to server2
> Now that is all fine according to microsofts article:
> http://support.microsoft.com/defaul...kb;en-us;224071
> However what i have noticed at times is that on server2, the logins are
> missing permissions to DB2. Why does this happen?
> Can things go missing if i perform it in this order:
> 1. place both server1 and server2 in single user mode via the -T3608
> parameter
> 2. detach model THEN msdb from Server1, copy them and move the copies to
> server2
> 3. attach model THEN msdb to server1 and server2
> 4. remove the -T3608 parameter and restart both sql services
> 5. i detach DB1
> 6. copy it (call it DB2)
> 7. attach DB1 to Server1 and DB2 to server2
> 8. script out the logins on server1 and apply them to server2
> ?
> Missing permissions occured when i did the above for our greatplains
> database.
> Any help appreciated.
> Cheers, john
>|||Logins are in master table and you dont have copied it to other server
Use sp_help_revlogin by microsoft to transfer login
http://support.microsoft.com/default.aspx?kbid=246133
OR
If login already exists on Server 2 then you need to map user to logins
in the DB2., since the SIDs are different on both the servers for the
login.
Regards
Amish|||thanks for the help Andrew and Amish.
I have always used the following article as my approach to scripting out the
logins:
http://www.support.microsoft.com/?id=246133
This has worked in the past.
The strange thing (i.e. when this was performed on the Greatplains database)
was that when i reattached all the databases back onto Server1 (and of
course the copies on server2), permissions went missing on server1 as well.
Is this particular to greatplains?
any help appreciated.
cheers, john
"amish" <shahamishm@.gmail.com> wrote in message
news:1135174050.693957.5380@.g14g2000cwa.googlegroups.com...
> Logins are in master table and you dont have copied it to other server
> Use sp_help_revlogin by microsoft to transfer login
> http://support.microsoft.com/default.aspx?kbid=246133
> OR
> If login already exists on Server 2 then you need to map user to logins
> in the DB2., since the SIDs are different on both the servers for the
> login.
> Regards
> Amish
>|||I am not quite sure what you did but have you tried the
sp_change_users_login to see if that helps?
Andrew J. Kelly SQL MVP
"john clarke" <jclarke@.nospam.com> wrote in message
news:ujPILOkBGHA.3840@.TK2MSFTNGP15.phx.gbl...
> thanks for the help Andrew and Amish.
> I have always used the following article as my approach to scripting out
> the logins:
> http://www.support.microsoft.com/?id=246133
> This has worked in the past.
> The strange thing (i.e. when this was performed on the Greatplains
> database) was that when i reattached all the databases back onto Server1
> (and of course the copies on server2), permissions went missing on server1
> as well.
> Is this particular to greatplains?
> any help appreciated.
> cheers, john
> "amish" <shahamishm@.gmail.com> wrote in message
> news:1135174050.693957.5380@.g14g2000cwa.googlegroups.com...
>

Wednesday, March 7, 2012

Desperatly Need Help with MSDE installation and Config

Hi all, I know read all the posts already up on this subject... Hear me out.

Can anyone give an easy to understand, and I mean easy method for installing MSDE and configuring it so that I can connect to my server using Visual Studio.NET C#. I am having no end of troubles and I don't really understand why. I can log into osql using

osql -S BIGJ -E

that gets me to

1>

No problems so far

but when I try to connect using

SqlConnection("Server=BIGJ;DataBase=registeredUsers;Integrated Security=SSPI");

I am having no luck and I don't really understand why

Here is the stack trace

[SqlException: Login failed for user 'BIGJ\ASPNET'.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
ADOAccess.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\adoaccess\webform1.aspx.cs:52
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()

I think I am not understanding the fundamentals of SQL server or something so if anyone can help or point me to a good tutorial that will help me not only solve my problem but also understand what is going onas well.

Thanks everyone

Hi

You must add the user "MACHINENAME\ASPNET" in your case "BIGJ\ASPNET" to every db you run in your PC (localhost), that way .net can log on the db.

To do that (and much more) you can use this free tool:

http://forums.asp.net/631069/ShowPost.aspx

Regards

|||

Thanks for the tip, I have SqlWDA installed but when I try and login it just hangs, I try using Windows integrated option and the SQL Login Option no luck just a frozen webpage.

Can you explain this, when I make a SqlConnection using Visual Studio dialog and press tesst connection it passes, if I copy that connection string into code I get the error I explained above? I'm really stuck

|||

/* Give ASPNET User login rights to the server database */

if not exists (select * from master.dbo.syslogins where loginname = N'MACHINE_NAME\ASPNET')
exec sp_grantlogin N'MACHINE_NAME\ASPNET'
exec sp_defaultdb N'MACHINE_NAME\ASPNET', N'DataBase'
exec sp_defaultlanguage N'MACHINE_NAME\ASPNET', N'us_english'
GO

/* Give ASPNET User Access to database */
use [DataBase]
GO

if not exists (select * from dbo.sysusers where name = N'ASPNET' and uid < 16382)
EXEC sp_grantdbaccess N'MACHINE_NAME\ASPNET', N'ASPNET'
GO

/* Regards */

Friday, February 17, 2012

design pattern question

Say I have an object that can be created by some users and not others. And, I have a method something like -function createObject(userId as Integer, objectName as String). The method calls a stored procedure using the two input arguments as parameters.
Now, what I am wondering is this; I am obviously going to check in my SP to ensure that the user has the rights to create the new object before inserting the new record, and there will be an output parameter to send the new record ID back to the method, but do I
a) have a separate output parameter to report on the success of the creation (e.g. @.Err Int OUTPUT)
b) use the existing output (used to send the new record ID back) and send an error code (e.g. if newRecordId = -9999)
c) somehow try to cause a failure of the SP that can be caught in a try/catch block
Thanks in advance,
MartinI would use option #2. Since you already have this variable, it can easily be checked for an error code and Im sure you are probably doing other types of checks as well. I would never ever ever use option #3. try/catches should always only be used from true exceptions. I always send myself an error email when a catch is experienced and would always be receiving these emails when there really wasnt an error.
Nick