SQL Server 2012 upgrade causing issue with Powershell multi-value update
How to get the real table names from dataset when use DataAdapter to exec a store procedure?
I have a SP which return several tables:
CREATEPROCEDURE [dbo].[USP_ExternalInterface_PersonalInfo_Select]--@Id nvarchar(19)ASBEGINSELECT * FROM Career --WHERE Id=@IdSELECT * FROM Education --WHERE Id=@Id--...END
And my C# code like below:
string connectionString = "server=.;database=ActivateCMBC;Integrated Security=true;Max Pool Size=100;Min Pool Size=10";string commandText = "EXEC USP_ExternalInterface_PersonalInfo_Select"; SqlDataAdapter adp=new SqlDataAdapter(commandText,connectionString); DataSet ds=new DataSet(); adp.FillSchema(ds, SchemaType.Source); adp.Fill(ds); foreach (DataTable dt in ds.Tables) { Console.WriteLine(dt.TableName); }
I want get real table names such as (Career, Education), but not (Table, Table1)
I hope I´ve made a good explication and you can help me. Thanks
Database refreshment
Hello sir,
We have data requirement to validate data in staging server before push the changes into production server.So we need database refreshment in staging server from latest copy from production server.This activity needs every month.
--What is the best method for database refreshment in every 20 days in staging(It is taking 10 hours).Database size is 1 TB.
--I have planned to configure log shipping on production server and make staging as secondary.
--Already we have log shipping set up on production server which is for disaster recovery.
--If do again log shipping set up on top of existing log shipping is there any issues or does not support?
Please advise better solution so that I minimize the time consuming for database refreshment in every 20 days.
Cheers,
Trigger to access another database as User
I am trying to set a trigger and have the trigger execute as a particular user, 'USER_A". "USER_A" exists as a user in the database(DATABASE_A). The trigger involves querying a table (TABLE_B) in another database(DATABASE_B). I therefore go to the SQL instance level and give "USERA" access to DATABASE_B. USER_A also exist in DATABASE_B with SELECT prermission on TABLE_B. However, when runing the trigger, I get the error
The server principal "USER_A" is not able to access the database "DATABASE_B" under the current security context.
My trigger looks like
ALTER TRIGGER triggername ON TableName
with execute as "USER_A"
AFTER INSERT AS
BEGIN
DECLARE @var varchar(20)SELECT TOP 1 @var = columnname FROM DATABASE_B.dbo.TABLE_B
END
How can I fix this please?
Odd issue with SQL SELECT using MAX
Hi everyone. I'm sorry to have to post on here about this, but I can't seem to figure out why this would be doing this.
I have the following SQL SELECT, which works perfectly.
SELECT Jobs.ID, Jobs.CustomerID AS [CustomerID], Jobs.ReferralID AS [ReferralID], Jobs.ReferralType, Jobs.AgentID AS [AgentID], Jobs.AdjusterID AS [AdjusterID], Jobs.EstimatorID AS [EstimatorID], Jobs.ManagerID AS [ManagerID], Jobs.JobType, COALESCE(NULLIF(Customers.Company,'') + ' - ','') + Customers.LName + ', ' + Customers.FName AS [Name], Jobs.InsuranceCompany, Jobs.DateReceived, MAX(BillingBid.DateCreated) AS [Bid Date], SUM(Billing.Amount) AS [Amount], StaffEstimator.FName + ' ' + StaffEstimator.LName AS [EstimatorName], StaffManager.FName + ' ' + StaffManager.LName AS [ManagerName], Jobs.JobStatus FROM Jobs LEFT OUTER JOIN Customers ON Customers.ID = Jobs.CustomerID LEFT OUTER JOIN Staff AS StaffEstimator ON StaffEstimator.ID = Jobs.EstimatorID LEFT OUTER JOIN Staff AS StaffManager ON StaffManager.ID = Jobs.ManagerID LEFT OUTER JOIN Billing AS BillingBid ON Jobs.ID = BillingBid.JobID AND BillingBid.BillingType = 'Bid' LEFT OUTER JOIN Billing ON Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No' WHERE Jobs.JobStatus = 'Active' AND (Jobs.DatePended IS NULL OR Jobs.DatePended <= '9/27/2014') GROUP BY Jobs.ID, Jobs.CustomerID, Jobs.ReferralID, Jobs.ReferralType, Jobs.AgentID, Jobs.AdjusterID, Jobs.EstimatorID, Jobs.ManagerID, Jobs.JobType, Customers.Company, Customers.LName, Customers.FName, Jobs.InsuranceCompany, Jobs.DateReceived, StaffEstimator.FName, StaffEstimator.LName, StaffManager.FName, StaffManager.LName, Jobs.JobStatus ORDER BY Name Asc
Now, I have a table for Communications, and want to add to this SQL Select, the Max Date from the Communications Table that relates to this Customer...
So I added that to the SQL Select like this:
SELECT Jobs.ID, Jobs.CustomerID AS [CustomerID], Jobs.ReferralID AS [ReferralID], Jobs.ReferralType, Jobs.AgentID AS [AgentID], Jobs.AdjusterID AS [AdjusterID], Jobs.EstimatorID AS [EstimatorID], Jobs.ManagerID AS [ManagerID], Jobs.JobType, COALESCE(NULLIF(Customers.Company,'') + ' - ','') + Customers.LName + ', ' + Customers.FName AS [Name], Jobs.InsuranceCompany, Jobs.DateReceived, MAX(BillingBid.DateCreated) AS [Bid Date], SUM(Billing.Amount) AS [Amount], StaffEstimator.FName + ' ' + StaffEstimator.LName AS [EstimatorName], StaffManager.FName + ' ' + StaffManager.LName AS [ManagerName], MAX(Communications.DateCreated) AS [Last Contact], Jobs.JobStatus FROM Jobs LEFT OUTER JOIN Customers ON Customers.ID = Jobs.CustomerID LEFT OUTER JOIN Staff AS StaffEstimator ON StaffEstimator.ID = Jobs.EstimatorID LEFT OUTER JOIN Staff AS StaffManager ON StaffManager.ID = Jobs.ManagerID LEFT OUTER JOIN Communications ON Jobs.CustomerID = Communications.ContactID AND Communications.ContactType = 'Customers' LEFT OUTER JOIN Billing AS BillingBid ON Jobs.ID = BillingBid.JobID AND BillingBid.BillingType = 'Bid' LEFT OUTER JOIN Billing ON Billing.JobID = Jobs.ID AND Billing.BillingType = 'Invoice' AND Billing.InvoiceCanceled = 'No' WHERE Jobs.JobStatus = 'Active' AND (Jobs.DatePended IS NULL OR Jobs.DatePended <= '9/27/2014') GROUP BY Jobs.ID, Jobs.CustomerID, Jobs.ReferralID, Jobs.ReferralType, Jobs.AgentID, Jobs.AdjusterID, Jobs.EstimatorID, Jobs.ManagerID, Jobs.JobType, Customers.Company, Customers.LName, Customers.FName, Jobs.InsuranceCompany, Jobs.DateReceived, Communications.DateCreated, StaffEstimator.FName, StaffEstimator.LName, StaffManager.FName, StaffManager.LName, Jobs.JobStatus ORDER BY Name Asc
Unfortunately, while I am asking for the MAX Communication that matches the Left Join, it is returning ALL of the Communications that match the Left Join...
Does anyone have any idea why this might be? No matter what I do I get the same result and I don't see anything wrong with the SQL Select... I'm sure I'm missing something stupid...
Thanks for your help,
-Matt-
How to read data using SQLGetData from a block, forward-only cursor (ODBC)
Hi there. I am trying to read data a small number of rows of data from either a Microsoft Access or Microsoft SQL Server (whichever is being used) as quickly as possible. I have connected to the database using the ODBC API's and have run a select statement using a forward-only, read-only cursor. I can use either SQLFetch or SQLExtendedFetch (with a rowset size of 1) to retrieve each successive row and then use SQLGetData to retrieve the data from each column into my local variables. This all works fine.
My goal is to see if I can improve performance incrementally by using SQLExtendedFetch with a rowset size greater than 1 (block cursor). However, I cannot figure out how to move to the first of the rowset returned so that I can call SQLGetData to retrieve each column. If I were using a cursor type that was not forward-only, I would use SQLSetPos to do this. However, using those other cursor types are slower and the whole point of the exercise is to see how fast I can read this data. I can successfully read the data using a block forward only cursor if I bind each column to an array in advance of the call to SQLExtendedFetch. However, that has several drawbacks and is documented to be slower for small numbers of rows. I really want to see what kind of speed I can achieve using a block, forward-only, read-only cursor using SQLGetData to get each column.
Here is the test stub that I created:
' Create a SELECT statement to retrieve the entire collection. selectString = "SELECT [Year] FROM REAssessmentRolls" ' Create a result set using the existing read/write connection. The read/write connection is used rather than ' the read-only connection because it will reflect the most recent changes made to the database by this running ' instance of the application without having to call RefreshReadCache. If (clsODBCDatabase.HandleDbcError(SQLAllocStmt(gDatabase.ReadWriteDbc, selectStmt), gDatabase.ReadWriteDbc, errorBoxTitle) <> enumODBCSQLAPIResult.SQL_SUCCESS) Then GoTo LoadExit End If Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_CONCURRENCY, SQL_CONCUR_READ_ONLY), selectStmt, errorBoxTitle) Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY), selectStmt, errorBoxTitle) Call clsODBCDatabase.HandleStmtError(SQLSetStmtOption(selectStmt, SQL_ROWSET_SIZE, MAX_ROWSET_SIZE), selectStmt, errorBoxTitle) If (clsODBCDatabase.HandleStmtError(SQLExecDirect(selectStmt, selectString, Len(selectString)), selectStmt, errorBoxTitle) <> enumODBCSQLAPIResult.SQL_SUCCESS) Then GoTo LoadExit End If ' Cursor through result set. Each time we fetch data we get a SET of rows. sqlResult = clsODBCDatabase.HandleStmtError(SQLExtendedFetch(selectStmt, SQL_FETCH_NEXT, 0, rowsFetched, rowStatus(0)), selectStmt, errorBoxTitle) Do While (sqlResult = enumODBCSQLAPIResult.SQL_SUCCESS) ' Read all rows in the row set For row = 1 To rowsFetched If rowStatus(row - 1) = SQL_ROW_SUCCESS Then sqlResult = clsODBCDatabase.HandleStmtError(SQLSetPos(selectStmt, row, SQL_POSITION, SQL_LOCK_NO_CHANGE), selectStmt, errorBoxTitle) Call clsODBCDatabase.SQLGetShortField(selectStmt, 1, assessmentRollYear(row - 1)) Console.WriteLine(assessmentRollYear(row - 1).ToString) End If Next ' If the rowset we just retrieved contains the maximum number of rows allowed, there could be more data. If rowsFetched = MAX_ROWSET_SIZE Then ' there could be more data sqlResult = clsODBCDatabase.HandleStmtError(SQLExtendedFetch(selectStmt, SQL_FETCH_NEXT, 0, rowsFetched, rowStatus(0)), selectStmt, errorBoxTitle) Else Exit Do ' no more rowsets End If Loop ' Do While (sqlResult = enumODBCSQLAPIResult.SQL_SUCCESS)
The test fails on the call to SQLSetPos. The error message I get is "Invalid cursor position; no keyset defined". I have tried passing SET_POSITION and also SET_REFRESH. Same error. There has to be a way to do this!
Thank you for your help!
Thank You! - Andy
Please Help me with this issue , in sql server 2012
when i connect to a project this message coming
TITLE: Connect to Server
------------------------------
Cannot connect to mydb.
------------------------------
ADDITIONAL INFORMATION:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)
why is this and how can i fix it?
Query the data between two tables
Need help for query the data between two tables
Table 1: Time sheet
P.ID P.Name EmpID HoursSpend DateTime
c12234 Test 25 4 06/12/2013
c12234 Test 25 7 06/13/2013
c12234 Test 25 8 06/15/2013
c12234 Test 5 3 06/21/2013
c12234 Test 2 5 07/15/2013
c12234 Test 25 4 07/21/2013
Table 2: cost table
EmpID FromDate ToDate Rate
25 05/01/2013 06/30/2013 250
2 04/01/2013 05/31/2013 150
25 07/01/2013 09/30/2013 300
Output
P.ID P.Name EmpID HoursSpend DateTime Rate Total (HoursSond x Rate)
c12234 Test 25 4 06/12/2013 250 1000 (4*250)
c12234 Test 25 7 06/13/2013 250 1750
c12234 Test 25 8 06/15/2013 250 2000
c12234 Test 25 4 07/21/2013 300 1200
c12234 Test 2 5 07/15/2013 150 750
===========================================
Total 28 6700
============================================
Here EmpID =2 don't have rate in the cost table on july month should be pick from last entry from cost table.
WIN XP CLIENT NOT ABLE TO ACCESS SQL 2008 ON WINDOWS SERVER 2008
Microsoft SQL Server Login
Conection Failed:
SQL State: '28000'
SQL Server Error: 18452
[Microsoft][ODBC SQL Server Driver][SQL Server] Login failed for user ''. The user is not associated with a trusted SQL Server connection.
I AM UNABLE TO CONNECT TO SQL INSTANCE INSTALLED ON WINDOWS SERVER 2008 FROM A NETWORKED XP CLIENT
I AM ABLE TO CONNECT VIA ADMINISTRATOR ACCOUNT ON BUT NOT ABLE TO CONNECT VIA DOMAIN OR LOCAL USER ID
I AM ABLE TO CONNECT FROM MY LAPTOP WHICH HAS WINDOWS SERVER 2008 ALSO INSTALLED.
SqlFileStream error: The network path was not found
I created a FileStream enabled table in a SQL2008 database, and populated some rows into it, from a SQL2000 table storing image. It's fine.
Then I wrote a WPF application in C#, trying to access the filestream data as below code snippet:
SqlConnection sqlConn = null;
SqlTransaction sqlTran = null;
try
{
// ids_static_imagesTableAdapter was defined by SQL SELECT statement:
// SELECT TOP (@x) image_name, image, image.PathName() AS image_path FROM dbo.ids_static_images
ids_static_imagesTableAdapter imgTa = new ids_static_imagesTableAdapter();
sqlConn = imgTa.Connection;
sqlConn.Open();
idsxi2011imageDataSet.ids_static_imagesDataTable imgDt = imgTa.GetData(10);
sqlTran = sqlConn.BeginTransaction();
SqlCommand cmdGetFsTxCtx = sqlConn.CreateCommand();
cmdGetFsTxCtx.CommandText = "SELECT GET_FILESTREAM_TRANSACTION_CONTEXT()";
cmdGetFsTxCtx.Transaction = sqlTran;
byte[] fileStreamTxCtx = (byte[])cmdGetFsTxCtx.ExecuteScalar();
foreach (idsxi2011imageDataSet.ids_static_imagesRow imgRow in imgDt)
{
SqlFileStream imgSqlFileStream = new SqlFileStream(imgRow.image_path, fileStreamTxCtx, FileAccess.Read);
Add(new ImageFile(imgRow.image_path, imgRow.image_name, imgSqlFileStream));
}
sqlTran.Commit();
}
finally
{
if (sqlConn != null && sqlConn.State == ConnectionState.Open)
{
sqlConn.Close();
}
}
The SqlFileStream constructor throws error, states 'The network path was not found'.
FYR, when I run the following SQL statement in SSMS:
SELECT TOP 1 image.PathName() AS image_path FROM dbo.ids_static_images
result as below:
\\XISERVER\MSSQLSERVER\v1\idsxi2011image\dbo\ids_static_images\image\3B121497-07E6-4568-9DDC-EFEAA57BE6AA
Any idea?
The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
We have a test db, a staging db and a live db. I have a stored procedure that runs fine on test and staging, but throws the following error on live.
The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
The stored procedure uses linked servers and a transaction.
We're using the following transaction code in the stored procedure
BEGINBEGINTRANSACTIONBEGINTRY---procedure stuff here
---
COMMITTRANSACTION
ENDTRY
BEGINCATCHDECLARE @ErrorSeverity INT, @ErrorNumber INT, @ErrorMessage NVARCHAR(4000), @ErrorState INTSET @ErrorSeverity = ERROR_SEVERITY()SET @ErrorNumber = ERROR_NUMBER()SET @ErrorMessage = ERROR_MESSAGE()SET @ErrorState = ERROR_STATE()IF @ErrorState = 0SET @ErrorState = 1RAISERROR('ERROR OCCURED:%d', @ErrorSeverity, @ErrorState, @ErrorNumber)IF XACT_STATE()< 0ROLLBACKTRANSACTIONENDCATCH ENDI found the following link which seems to be the problem we're experiencing
http://support.microsoft.com/kb/937517
The link includes a workaround which is the following:
ODBC Array of Parameters and Individual Affected Row Counts
I am executing a prepared DELETE statement on an array or parameters. The problem is with getting the number of rows affected (deleted) by each of the parameter set. According to the documentation[1], whether this information is available is determined by the SQL_PARAM_ARRAYS_ROW_COUNTS property as returned by SQLGetInfo. If the value of this property is SQL_PARC_BATCH, then the individual counts should are available.
While the SQL Server native client returns SQL_PARC_BATCH, the behavior I am observing is exactly the opposite. That is, the first call to SQLRowCount returns the total number of affected rows by all the elements in the array of parameters. And calling SQLMoreResult gets me SQL_NO_DATA.
Also, the documentation for SQLRowCount from the Native Client ODBC reference[2] seems to imply that this function returns the total count.
So that's the inconsistency that I am observing. Can someone from the ODBC product team confirm that only total count is available? Also, if you can suggest a way to get individual counts, that would be very helpful.
[1] http://msdn.microsoft.com/en-us/library/ms714039(v=vs.85).aspx
[2] http://msdn.microsoft.com/en-us/library/ms131352.aspx
Calling Stored procedure from MS Access
Hi! Please help me to understand if possible. I am migrating from accdb (Access 2007) to MSSQL BE and trying to rewrite queries due to performance problem. My question is that I need to use Stored Procedure and call it from Access. I created simple stored procedure as a test:
CREATE PROC Test1 (@Param AS INT)
SELECT* FROM dbo.BOM WHEREdbo.BOM.Customer=@Param
and calling EXEC Test1 10 from MS ACCESS Pass Thru Query no problem. All works fine and I get value 10 being passed to Stored Procedure and I get right results . Now, how can I assign Access Form Control value in place of value 10? Like Forms![Test]![Text1]? I tried different things like Declaring variable but no luck. Please help
how to make sure no one can see the back end in ms access 2013?
linked server impersonation for login mapped to certificate
I currently implemented the use of certificates for SP's and have a question on how to get the account mapped to a linked server.
http://www.sommarskog.se/grantperm.html
When I run the stored procedure in SSMS it runs fine but when I add it to a job and make the job owner a non sysadmin, I get the following error.
Linked servers cannot be used under impersonation without a mapping for the impersonated login. [SQLSTATE 42000] (Error 7437). The step failed.
When I try and add the login to linked server impersonation it fails and says the account doesn't exist. A lot of the stored procedures that are signed with a certificate use a linked server connection.
Thanks!
Unable to create dataset against OLAP Cube from different server
Hi guys,
If I load Microsoft SQL Report Builder on the BI Server, I am able to create a dataset against the OLAP Cube I created on the BI Server, however if I try to run the Report Builder from a different server I get the following error:
"Unable to connect to data source 'MyOLAPCube'.
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 172.20.112.82:2382
------------------
A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running."
I have had no issues starting the SQL Browser service, however if I try to run it in console mode, I get the following error:
'SQLBrowser: Warning: failed starting OLAP redirection services with error 1.'
I have checked online and seen a few similar issues online however I haven't been able to resolve my issue with their resolution.
Any help is appreciated.
Many thanks
Richard
How to get the real table names from dataset when use DataAdapter to exec a store procedure?
I have a SP which return several tables:
CREATEPROCEDURE [dbo].[USP_ExternalInterface_PersonalInfo_Select]--@Id nvarchar(19)ASBEGINSELECT * FROM Career --WHERE Id=@IdSELECT * FROM Education --WHERE Id=@Id--...END
And my C# code like below:
string connectionString = "server=.;database=ActivateCMBC;Integrated Security=true;Max Pool Size=100;Min Pool Size=10";string commandText = "EXEC USP_ExternalInterface_PersonalInfo_Select"; SqlDataAdapter adp=new SqlDataAdapter(commandText,connectionString); DataSet ds=new DataSet(); adp.FillSchema(ds, SchemaType.Source); adp.Fill(ds); foreach (DataTable dt in ds.Tables) { Console.WriteLine(dt.TableName); }
I want get real table names such as (Career, Education), but not (Table, Table1)
I hope I´ve made a good explication and you can help me. Thanks
Database refreshment
Hello sir,
We have data requirement to validate data in staging server before push the changes into production server.So we need database refreshment in staging server from latest copy from production server.This activity needs every month.
--What is the best method for database refreshment in every 20 days in staging(It is taking 10 hours).Database size is 1 TB.
--I have planned to configure log shipping on production server and make staging as secondary.
--Already we have log shipping set up on production server which is for disaster recovery.
--If do again log shipping set up on top of existing log shipping is there any issues or does not support?
Please advise better solution so that I minimize the time consuming for database refreshment in every 20 days.
Cheers,
Trigger to access another database as User
I am trying to set a trigger and have the trigger execute as a particular user, 'USER_A". "USER_A" exists as a user in the database(DATABASE_A). The trigger involves querying a table (TABLE_B) in another database(DATABASE_B). I therefore go to the SQL instance level and give "USERA" access to DATABASE_B. USER_A also exist in DATABASE_B with SELECT prermission on TABLE_B. However, when runing the trigger, I get the error
The server principal "USER_A" is not able to access the database "DATABASE_B" under the current security context.
My trigger looks like
ALTER TRIGGER triggername ON TableName
with execute as "USER_A"
AFTER INSERT AS
BEGIN
DECLARE @var varchar(20)SELECT TOP 1 @var = columnname FROM DATABASE_B.dbo.TABLE_B
END
How can I fix this please?
MSDTC Error 1206, Severity 18, State 101
Need some help here.. we're encountering an msdtc error 1206 when we do inserts from entity framework into SQL Server 2012
Initially we had the error "There was an error reading from the pipe".
We do not have any more info on this, but maybe some of you already had this error...
Thanks,
J.
Jurgen Asselman
MCITP SQL Server 2008 - Database Developer
SQL Server 2012 adept