Showing posts with label everybody. Show all posts
Showing posts with label everybody. Show all posts

Wednesday, March 28, 2012

No exception message from CLR stored procedure

Hello everybody,

I've encountered a strange thing using a CLR Stored procedure:

The procedure throws an exception with no message inside... value = {" "}

Basically the procedure has a string as argument which contains a SQL statement that changes according to the users selections...

The results of the query are saved into a dataset for further processing.

Those resultsets can sometimes be very big (ex: 15000 records...). (For the record the procedure works fine for smaller datasets ex 6000 records and running the same query on the application server returns the expected resultset )

By Debugging the procedure I could determine that the failing point was when the dataset is filled...

Anyone having any idea?

The only information I have from this exception is the stacktrace:

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlDataReader.CloseInternal(Boolean closeReader)

at System.Data.SqlClient.SqlDataReader.Close()

at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)

at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteScalar()

at DataAccess.runScalar(String strSQL, Boolean isStoredProcedure) in c:\Inetpub\wwwroot\Statistix\App_Code\DataAccess.cs:line 114

Thanks in advance

Alaindlk

Hello,

Still nobody having any idea of what is happening here?

Could it be possible that the SQL server is running out of memory or even having a connection timeout?

this is the procedure I've written that causes this behaviour:

[Microsoft.SqlServer.Server.SqlProcedure]

public static int Stats_Print_Data(string SqlQuery)

{

// Put your code here

int jobId = -1;

using (DataSet dsResults = new DataSet())

{

using (SqlConnection mConn = new SqlConnection("context connection = true"))

{

SqlCommand mCmd = new SqlCommand(SqlQuery, mConn);

mCmd.CommandTimeout = 100;

SqlDataAdapter mDa = new SqlDataAdapter(mCmd);

mDa.Fill(dsResults, "Print_Data");

if (dsResults.Tables[0].Rows.Count > 0)

{

ArrayList ColumnNames = new ArrayList();

for (int i = 8; i < dsResults.Tables[0].Columns.Count; i++)

{

DataColumn dc = dsResults.Tables[0].ColumnsIdea;

ColumnNames.Add(dc.ColumnName);

}

StringBuilder InsertCommand = new StringBuilder();

StringBuilder Values = new StringBuilder();

try

{

mConn.Open();

mCmd.CommandText = "Select max(report_id) from Statistix_Report";

jobId = System.Convert.ToInt16(mCmd.ExecuteScalar());

jobId++;

foreach (DataRow dr in dsResults.Tables[0].Rows)

{

if (InsertCommand.Length > 0) InsertCommand.Remove(0, InsertCommand.Length);

if (Values.Length > 0) Values.Remove(0, Values.Length);

mCmd.CommandText = "Select count(*) from print_data where AG_LIB = '" + dr[2].ToString().Replace("'", "''") +

"' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''") +

"' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + drDevil.ToString().Replace("'", "''") +

"' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "'";

if (System.Convert.ToInt16(mCmd.ExecuteScalar()) > 0)

{

InsertCommand.Append("Update PRINT_DATA set ");

for (int i = 0; i < ColumnNames.Count; i++)

{

InsertCommand.Append(ColumnNamesIdea + "_" + int.Parse(dr["Month"].ToString()) + " = ");

if (dr[i + 8] != DBNull.Value)

{

InsertCommand.Append(dr[i + 8].ToString().Replace(",", "."));

}

else

{

InsertCommand.Append("0");

}

if (i != ColumnNames.Count - 1)

{

InsertCommand.Append(",");

}

}

InsertCommand.Append(" where AG_LIB = '" + dr[2].ToString().Replace("'", "''"));

InsertCommand.Append("' and AN_LIB = '" + dr[3].ToString().Replace("'", "''") + "' and PRD_LIB = '" + dr[4].ToString().Replace("'", "''"));

InsertCommand.Append("' and TM_LIB = '" + dr[5].ToString().Replace("'", "''") + "' and RM_LIB = '" + drDevil.ToString().Replace("'", "''"));

InsertCommand.Append("' and SU_LIB = '" + dr[7].ToString().Replace("'", "''") + "' and JOB_ID = " + jobId);

mCmd.CommandText = InsertCommand.ToString();

mCmd.ExecuteNonQuery();

}

else

{

Values = new StringBuilder();

InsertCommand = new StringBuilder();

InsertCommand.Append("insert into print_data(AG_LIB,AN_LIB,PRD_LIB,TM_LIB,RM_LIB,SU_LIB,JOB_ID,");

Values.Append("'" + dr[2].ToString().Replace("'", "''") + "','" + dr[3].ToString().Replace("'", "''") + "','");

Values.Append(dr[4].ToString().Replace("'", "''") + "','" + dr[5].ToString().Replace("'", "''") + "','");

Values.Append(drDevil.ToString().Replace("'", "''") + "','" + dr[7].ToString().Replace("'", "''") + "'," + jobId + ",");

for (int i = 0; i < ColumnNames.Count; i++)

{

InsertCommand.Append(ColumnNamesIdea + "_" + int.Parse(dr["Month"].ToString()));

if (dr[i + 8] != DBNull.Value)

{

Values.Append(dr[i + 8].ToString().Replace(",", "."));

}

else Values.Append("0");

if (i != ColumnNames.Count - 1)

{

InsertCommand.Append(",");

Values.Append(",");

}

}

InsertCommand.Append(") values (");

InsertCommand.Append(Values.ToString() + ")");

mCmd.CommandText = InsertCommand.ToString();

mCmd.ExecuteNonQuery();

}

}

}

catch (Exception ex)

{

throw new Exception(InsertCommand.ToString(), ex);

}

finally

{

mCmd.Dispose();

mConn.Close();

}

}

}

}

return jobId;

}

Any help would be greatly appreciated...

How can i debug something like this?

Thanks in advance

|||

Are you sure that it is the error message thrown by SqlClient is empty and not the exception you throw here:

catch (Exception ex)

{

throw new Exception(InsertCommand.ToString(), ex);

}

? What happens if you remove this catch block and let the unhandled exception get propogated back to sql server - is it still empty?

|||

Hello Steven,

Thanks for your reply...

The exception I've given above is effectively thrown by the stored procedure...

Further investigation learned me that it was indeed a timeout of the stored procedure, so I deed improve the indexing on the tables which now solves partly my problem...

However The problem still remains as the stored procedure, after fetching the required data, saves this data into a table for reporting. The problem is that each 12 rows in the dataset has to be transformed as one record with 12 columns (Table sucks but I have to work with this solution imposed to me ) This means I first need to know if the record already exists, if not then create an insert statement else create an update statement.
Now it seems that executing this causes a timeout for the procedure.
Is there any way to increase this timeout period?

|||

Hello everybody,

I think I've finally found the reason why this timeout occurs: Thats because of the fact that the stored procedure returns a value...
In the worst case, my procedure takes about 10 minutes to complete.... letting the Application server waiting that long is "unacceptable". I think that SQL server automatically throws a timeout exception whenever a procedure/ function takes to long to complete.
I've solved this by changing the procedure signature from Static int SP_Name to static void SP_name(); This way the procedure doesn't have to return a value and isn't any more interrupted by a timeout thrown by SQL server...

Can anyone confirm me this behaviour of SQL server? (By the way this solution works fine for me now...)

Thanks in advance

Friday, March 23, 2012

No data in Sql server 2005

Hi everybody,
Happy Holidays to all. I developed a windows application that connects to
Sql server 2000, using windows authentication and it works, able to retrive
and other data process. But when I used it on Sql Server 2005 Express, it wa
s
unable to retrive data. What is wrong with it? How can I fixed this?
Connecting String at 2000:
"integrated security=SSPI;data source=localhost;persist security
info=False;initial
catalog=Genesis;"
Connection String at 2005:
"integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist securit
y
info=False;initial catalog=Genesis;"
"user id=guest;password=guest123;data source=RITS-DENNIS\SQLEXPRESS;persist
security info=False;initial catalog=Genesis;"
Thanks in Advanced.
den2005
--
MCP Year 2005, PhilippinesHi,
would you give some more insight !?
is it run on Windows Authentication !?
is their Guest User has access for DB / server !?
what is error message ?
:-)
Regards
--
Andy Davis
Activecrypt Team
---
SQL Server Encryption Software
http://www.activecrypt.com
"den 2005" wrote:

> Hi everybody,
> Happy Holidays to all. I developed a windows application that connects
to
> Sql server 2000, using windows authentication and it works, able to retriv
e
> and other data process. But when I used it on Sql Server 2005 Express, it
was
> unable to retrive data. What is wrong with it? How can I fixed this?
> Connecting String at 2000:
> "integrated security=SSPI;data source=localhost;persist security
> info=False;initial
> catalog=Genesis;"
> Connection String at 2005:
> "integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist secur
ity
> info=False;initial catalog=Genesis;"
> "user id=guest;password=guest123;data source=RITS-DENNIS\SQLEXPRESS;persis
t
> security info=False;initial catalog=Genesis;"
>
> Thanks in Advanced.
> den2005
> --
> MCP Year 2005, Philippines|||Please don't post independently in separate newsgroups. You can add
multiple newsgroups to the header and then all the answers appear as one.
See my reply in the other newsgroup.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:B4D11A55-9CB7-4ACE-9F4E-91524D4E58D9@.microsoft.com...
> Hi everybody,
> Happy Holidays to all. I developed a windows application that connects
> to
> Sql server 2000, using windows authentication and it works, able to
> retrive
> and other data process. But when I used it on Sql Server 2005 Express, it
> was
> unable to retrive data. What is wrong with it? How can I fixed this?
> Connecting String at 2000:
> "integrated security=SSPI;data source=localhost;persist security
> info=False;initial
> catalog=Genesis;"
> Connection String at 2005:
> "integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist
> security
> info=False;initial catalog=Genesis;"
> "user id=guest;password=guest123;data
> source=RITS-DENNIS\SQLEXPRESS;persist
> security info=False;initial catalog=Genesis;"
>
> Thanks in Advanced.
> den2005
> --
> MCP Year 2005, Philippines|||Thanks Andy for replying.
The connection is ok. Able to connect and open the SqlConnection but no data
is retrive, but teher is data on it. I used windows authentication in sql
2000 and try this in sql 2005.
Dennis
--
MCP Year 2005, Philippines
"Andy Davis" wrote:
[vbcol=seagreen]
> Hi,
> would you give some more insight !?
> is it run on Windows Authentication !?
> is their Guest User has access for DB / server !?
> what is error message ?
> :-)
> Regards
> --
> Andy Davis
> Activecrypt Team
> ---
> SQL Server Encryption Software
> http://www.activecrypt.com
>
> "den 2005" wrote:
>|||Sorry for that, don't know how to do that.
dennis
--
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> Please don't post independently in separate newsgroups. You can add
> multiple newsgroups to the header and then all the answers appear as one.
> See my reply in the other newsgroup.
>
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:B4D11A55-9CB7-4ACE-9F4E-91524D4E58D9@.microsoft.com...
>
>|||You simply include the other newsgroups in the "NewsGroups" (addressed to
part of the header) section and it will be posted to all of them at once,
including replies. If you have Outlook Express you can simply click on the
"Newsgroups" icon to the left of the textbox and select as many as you need.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:08CE0F6F-5D4F-4152-8E4C-45DA8366E681@.microsoft.com...[vbcol=seagreen]
> Sorry for that, don't know how to do that.
> dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
>|||In the headers of den2005's messages it says that the Newsreader is
"Microsoft CDO for Windows 2000", so it seems to not be Outlook Express. I
think it is probably an online Newsreader.
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23oI1TyuCGHA.724@.TK2MSFTNGP10.phx.gbl...
> If you have Outlook Express you can simply click on the "Newsgroups" icon
> to the left of the textbox and select as many as you need.|||Hi Andrew and Sam,
I am using the Microsof Online Newsgroup to post topics and not using
Outlook.
den2005
--
MCP Year 2005, Philippines
"Sam Hobbs" wrote:

> In the headers of den2005's messages it says that the Newsreader is
> "Microsoft CDO for Windows 2000", so it seems to not be Outlook Express. I
> think it is probably an online Newsreader.
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23oI1TyuCGHA.724@.TK2MSFTNGP10.phx.gbl...
>
>|||Hi,
have you created a new database ! or attached it !?
:-)
Regards
--
Andy Davis
Activecrypt Team
---
SQL Server Encryption Software
http://www.activecrypt.com
"den 2005" wrote:
[vbcol=seagreen]
> Thanks Andy for replying.
> The connection is ok. Able to connect and open the SqlConnection but no da
ta
> is retrive, but teher is data on it. I used windows authentication in sql
> 2000 and try this in sql 2005.
> Dennis
> --
> MCP Year 2005, Philippines
>
> "Andy Davis" wrote:
>|||Hi Den
The Web based newsgroups such as
http://www.microsoft.com/technet/co...server/sql.mspx do not
allow you to post in multiple groups. You should choose the most appropriate
group and post there. Before posting it is also worth checking for similar
posts made in the past, e.g. search google (which would cover multiple
groups) or using the search facility in the online groups.
John
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:21A14991-A08A-4A51-B2CE-D48A6C51FDA0@.microsoft.com...[vbcol=seagreen]
> Hi Andrew and Sam,
> I am using the Microsof Online Newsgroup to post topics and not using
> Outlook.
> den2005
> --
> MCP Year 2005, Philippines
>
> "Sam Hobbs" wrote:
>

No data in Sql 2005 tehre is data in sql 2000

Hi everybody,
I developed a windows application that connects to Sql server 2000, using
windows authentication and it works, able to retrive and other data process.
But when I used it on Sql Server 2005 Express, it was unable to retrive data
.
What is wrong with it? How can I fixed this?
Connecting String at 2000:
"integrated security=SSPI;data source=localhost;persist security
info=False;initial
catalog=Genesis;"
Connection String at 2005:
"integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist securit
y
info=False;initial catalog=Genesis;"
"user id=guest;password=guest123;data source=RITS-DENNIS\SQLEXPRESS;persist
security info=False;initial catalog=Genesis;"
Thanks in Advanced.
den2005
--
MCP Year 2005, PhilippinesWhat exactly does "unable to retrieve data" mean? Is it a problem
connecting to SQL Server? Do you get errors when you run queries? Do you
not get errors but no data? It could be a million things you have to help
us out here.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:4CA57567-F7CD-42C0-B588-4609ADFB5730@.microsoft.com...
> Hi everybody,
> I developed a windows application that connects to Sql server 2000,
> using
> windows authentication and it works, able to retrive and other data
> process.
> But when I used it on Sql Server 2005 Express, it was unable to retrive
> data.
> What is wrong with it? How can I fixed this?
> Connecting String at 2000:
> "integrated security=SSPI;data source=localhost;persist security
> info=False;initial
> catalog=Genesis;"
> Connection String at 2005:
> "integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist
> security
> info=False;initial catalog=Genesis;"
> "user id=guest;password=guest123;data
> source=RITS-DENNIS\SQLEXPRESS;persist
> security info=False;initial catalog=Genesis;"
>
> Thanks in Advanced.
> den2005
> --
> MCP Year 2005, Philippines|||Thanks for replying, Andrew.
Able to open SqlConnection but no data is returned or retrived, and no error
message either.
Dennis
--
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> What exactly does "unable to retrieve data" mean? Is it a problem
> connecting to SQL Server? Do you get errors when you run queries? Do you
> not get errors but no data? It could be a million things you have to help
> us out here.
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:4CA57567-F7CD-42C0-B588-4609ADFB5730@.microsoft.com...
>
>|||Again we need as much info as you can give us. Your initial post shows only
a connection string. There is no example of what you are doing after that.
Just opening a connection does not return data, you need to issue a
statement. Can you post the exact code you are using to issue the command
and how you are determining it does not return anything?
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:4867BFEF-7E1E-4C73-9033-9001EAAA90F7@.microsoft.com...[vbcol=seagreen]
> Thanks for replying, Andrew.
> Able to open SqlConnection but no data is returned or retrived, and no
> error
> message either.
> Dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
>|||Hi Andrew,
Thanks for reply. Well, I have found what is wrong, and able to retrive
data. There ia one strange incident involving storing data, I inserted a lot
of records in SQl server 2005 using Windows authentication to log on the sql
server, the other day, I look into the data and it's gone, seems the data ha
s
been erased or was not all inserted permanently.
Yesterday, I used the sa account to do the same, today, I check the data
inserted yesterday was still here. Why does that happens? Using windows
authentication to insert data is not ok. I am doing this in sql 2000, and it
is working.
Solved Problem Codes: (This is not exact code, Basically this is what trying
to do)
Dim sqlConn As New SqlConnection(constr)
Dim sqlText = "Select * From Topics"
Dim sqlAdapter As new SqlDataAdapter(sqlText, sqlConn)
Dim ds as new DataSet
sqlAdapter.Fill(ds,"Topics')
Dim dtObj as Datatable
dtObj = ds.Tables("Topics")
return dtObj
dennis
--
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> Again we need as much info as you can give us. Your initial post shows onl
y
> a connection string. There is no example of what you are doing after that.
> Just opening a connection does not return data, you need to issue a
> statement. Can you post the exact code you are using to issue the command
> and how you are determining it does not return anything?
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:4867BFEF-7E1E-4C73-9033-9001EAAA90F7@.microsoft.com...
>
>|||The reason you seemed to have lost the data was probably due to the
connection setting it in IMPLICIT TRANSACTION mode. This means when the
first command is issued a BEGIN TRAN automatically gets issued behind the
scenes. That means all of your inserts were wrapped in a transaction. If
you didn't issue a COMMIT when done they would have been rolled back when
you ended the connection.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:B01C3A0C-6F8E-40DF-BCF6-2E137D78EE13@.microsoft.com...[vbcol=seagreen]
> Hi Andrew,
> Thanks for reply. Well, I have found what is wrong, and able to retrive
> data. There ia one strange incident involving storing data, I inserted a
> lot
> of records in SQl server 2005 using Windows authentication to log on the
> sql
> server, the other day, I look into the data and it's gone, seems the data
> has
> been erased or was not all inserted permanently.
> Yesterday, I used the sa account to do the same, today, I check the
> data
> inserted yesterday was still here. Why does that happens? Using windows
> authentication to insert data is not ok. I am doing this in sql 2000, and
> it
> is working.
> Solved Problem Codes: (This is not exact code, Basically this is what
> trying
> to do)
> Dim sqlConn As New SqlConnection(constr)
> Dim sqlText = "Select * From Topics"
> Dim sqlAdapter As new SqlDataAdapter(sqlText, sqlConn)
> Dim ds as new DataSet
> sqlAdapter.Fill(ds,"Topics')
> Dim dtObj as Datatable
> dtObj = ds.Tables("Topics")
> return dtObj
>
> dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
>|||Andrew,
Transaction? I did not use them, I used the query window and put insert
statements and execute by pressing F5. Is there a automatic transaction mode
at the back of this operation? I used sa account, why i did not lose the dat
a
same as before, the change I did is only the account I used to login.
Thanks for reply.
dennis
--
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> The reason you seemed to have lost the data was probably due to the
> connection setting it in IMPLICIT TRANSACTION mode. This means when the
> first command is issued a BEGIN TRAN automatically gets issued behind the
> scenes. That means all of your inserts were wrapped in a transaction. If
> you didn't issue a COMMIT when done they would have been rolled back when
> you ended the connection.
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:B01C3A0C-6F8E-40DF-BCF6-2E137D78EE13@.microsoft.com...
>
>|||By default the Query Editor does not use Implicit Transactions but you can
change the options to be in that mode. It is hard to say what actually
happened but most of the time people ask about something like this it is the
result of an inadvertent BEGIN TRAN and no COMMIT.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:7E08B896-BBD9-4D0C-B5AD-8C3A21D6EB53@.microsoft.com...[vbcol=seagreen]
> Andrew,
> Transaction? I did not use them, I used the query window and put insert
> statements and execute by pressing F5. Is there a automatic transaction
> mode
> at the back of this operation? I used sa account, why i did not lose the
> data
> same as before, the change I did is only the account I used to login.
> Thanks for reply.
> dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
>

No data in Sql 2005 tehre is data in sql 2000

Hi everybody,
I developed a windows application that connects to Sql server 2000, using
windows authentication and it works, able to retrive and other data process.
But when I used it on Sql Server 2005 Express, it was unable to retrive data.
What is wrong with it? How can I fixed this?
Connecting String at 2000:
"integrated security=SSPI;data source=localhost;persist security
info=False;initial
catalog=Genesis;"
Connection String at 2005:
"integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist security
info=False;initial catalog=Genesis;"
"user id=guest;password=guest123;data source=RITS-DENNIS\SQLEXPRESS;persist
security info=False;initial catalog=Genesis;"
Thanks in Advanced.
den2005
MCP Year 2005, Philippines
What exactly does "unable to retrieve data" mean? Is it a problem
connecting to SQL Server? Do you get errors when you run queries? Do you
not get errors but no data? It could be a million things you have to help
us out here.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:4CA57567-F7CD-42C0-B588-4609ADFB5730@.microsoft.com...
> Hi everybody,
> I developed a windows application that connects to Sql server 2000,
> using
> windows authentication and it works, able to retrive and other data
> process.
> But when I used it on Sql Server 2005 Express, it was unable to retrive
> data.
> What is wrong with it? How can I fixed this?
> Connecting String at 2000:
> "integrated security=SSPI;data source=localhost;persist security
> info=False;initial
> catalog=Genesis;"
> Connection String at 2005:
> "integrated security=SSPI;data source=RITS-DENNIS\SQLEXPRESS;persist
> security
> info=False;initial catalog=Genesis;"
> "user id=guest;password=guest123;data
> source=RITS-DENNIS\SQLEXPRESS;persist
> security info=False;initial catalog=Genesis;"
>
> Thanks in Advanced.
> den2005
> --
> MCP Year 2005, Philippines
|||Thanks for replying, Andrew.
Able to open SqlConnection but no data is returned or retrived, and no error
message either.
Dennis
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> What exactly does "unable to retrieve data" mean? Is it a problem
> connecting to SQL Server? Do you get errors when you run queries? Do you
> not get errors but no data? It could be a million things you have to help
> us out here.
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:4CA57567-F7CD-42C0-B588-4609ADFB5730@.microsoft.com...
>
>
|||Again we need as much info as you can give us. Your initial post shows only
a connection string. There is no example of what you are doing after that.
Just opening a connection does not return data, you need to issue a
statement. Can you post the exact code you are using to issue the command
and how you are determining it does not return anything?
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:4867BFEF-7E1E-4C73-9033-9001EAAA90F7@.microsoft.com...[vbcol=seagreen]
> Thanks for replying, Andrew.
> Able to open SqlConnection but no data is returned or retrived, and no
> error
> message either.
> Dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
|||Hi Andrew,
Thanks for reply. Well, I have found what is wrong, and able to retrive
data. There ia one strange incident involving storing data, I inserted a lot
of records in SQl server 2005 using Windows authentication to log on the sql
server, the other day, I look into the data and it's gone, seems the data has
been erased or was not all inserted permanently.
Yesterday, I used the sa account to do the same, today, I check the data
inserted yesterday was still here. Why does that happens? Using windows
authentication to insert data is not ok. I am doing this in sql 2000, and it
is working.
Solved Problem Codes: (This is not exact code, Basically this is what trying
to do)
Dim sqlConn As New SqlConnection(constr)
Dim sqlText = "Select * From Topics"
Dim sqlAdapter As new SqlDataAdapter(sqlText, sqlConn)
Dim ds as new DataSet
sqlAdapter.Fill(ds,"Topics')
Dim dtObj as Datatable
dtObj = ds.Tables("Topics")
return dtObj
dennis
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> Again we need as much info as you can give us. Your initial post shows only
> a connection string. There is no example of what you are doing after that.
> Just opening a connection does not return data, you need to issue a
> statement. Can you post the exact code you are using to issue the command
> and how you are determining it does not return anything?
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:4867BFEF-7E1E-4C73-9033-9001EAAA90F7@.microsoft.com...
>
>
|||The reason you seemed to have lost the data was probably due to the
connection setting it in IMPLICIT TRANSACTION mode. This means when the
first command is issued a BEGIN TRAN automatically gets issued behind the
scenes. That means all of your inserts were wrapped in a transaction. If
you didn't issue a COMMIT when done they would have been rolled back when
you ended the connection.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:B01C3A0C-6F8E-40DF-BCF6-2E137D78EE13@.microsoft.com...[vbcol=seagreen]
> Hi Andrew,
> Thanks for reply. Well, I have found what is wrong, and able to retrive
> data. There ia one strange incident involving storing data, I inserted a
> lot
> of records in SQl server 2005 using Windows authentication to log on the
> sql
> server, the other day, I look into the data and it's gone, seems the data
> has
> been erased or was not all inserted permanently.
> Yesterday, I used the sa account to do the same, today, I check the
> data
> inserted yesterday was still here. Why does that happens? Using windows
> authentication to insert data is not ok. I am doing this in sql 2000, and
> it
> is working.
> Solved Problem Codes: (This is not exact code, Basically this is what
> trying
> to do)
> Dim sqlConn As New SqlConnection(constr)
> Dim sqlText = "Select * From Topics"
> Dim sqlAdapter As new SqlDataAdapter(sqlText, sqlConn)
> Dim ds as new DataSet
> sqlAdapter.Fill(ds,"Topics')
> Dim dtObj as Datatable
> dtObj = ds.Tables("Topics")
> return dtObj
>
> dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
|||Andrew,
Transaction? I did not use them, I used the query window and put insert
statements and execute by pressing F5. Is there a automatic transaction mode
at the back of this operation? I used sa account, why i did not lose the data
same as before, the change I did is only the account I used to login.
Thanks for reply.
dennis
MCP Year 2005, Philippines
"Andrew J. Kelly" wrote:

> The reason you seemed to have lost the data was probably due to the
> connection setting it in IMPLICIT TRANSACTION mode. This means when the
> first command is issued a BEGIN TRAN automatically gets issued behind the
> scenes. That means all of your inserts were wrapped in a transaction. If
> you didn't issue a COMMIT when done they would have been rolled back when
> you ended the connection.
> --
> Andrew J. Kelly SQL MVP
>
> "den 2005" <den2005@.discussions.microsoft.com> wrote in message
> news:B01C3A0C-6F8E-40DF-BCF6-2E137D78EE13@.microsoft.com...
>
>
|||By default the Query Editor does not use Implicit Transactions but you can
change the options to be in that mode. It is hard to say what actually
happened but most of the time people ask about something like this it is the
result of an inadvertent BEGIN TRAN and no COMMIT.
Andrew J. Kelly SQL MVP
"den 2005" <den2005@.discussions.microsoft.com> wrote in message
news:7E08B896-BBD9-4D0C-B5AD-8C3A21D6EB53@.microsoft.com...[vbcol=seagreen]
> Andrew,
> Transaction? I did not use them, I used the query window and put insert
> statements and execute by pressing F5. Is there a automatic transaction
> mode
> at the back of this operation? I used sa account, why i did not lose the
> data
> same as before, the change I did is only the account I used to login.
> Thanks for reply.
> dennis
> --
> MCP Year 2005, Philippines
>
> "Andrew J. Kelly" wrote:
sql

Monday, March 12, 2012

NextDay

Hello everybody?

Another issue has cropped up in my Oracle to SQL Svr migration. Can anybody suggest the equivalent code for the Oracle NEXT_DAY function?

Here is a sample of how Oracle NEXT_DAY function works...

SELECT NEXT_DAY(sysdate, 'Sunday') from dual ;

Result:

NEXT_DAY
---
12-DEC-04

where sysdate is Oracle for GetDate() of SQL Svr. Forget about "from dual". So, what NEXT_DAY is doing is that it is returning the next coming date on which a Sunday will fall, if sysdate = 07 Dec 2004.

Any help will be highly appreciated. ThxYou'll have to write this youself, as there is no immediate equivalent.
You can pretty easily create a user-defined function that exactly mimics oracle NEXT_DAY()

You would have to use the SQL function datename(weekday, date)
and the SQL function dateadd(day, 1, date).
Loop round a max of seven (six?) times using dateadd to add a day to your date, and then using datename to get the day description which you could then compare with your input parameter. return the appropraite date when a match is found.

HTH, but I ain't coding it for you :-)

Bill|||Here is a non-looping algorithm:

declare @.TargetDay int
set @.TargetDay = 1 --Sunday
select dateadd(d, (@.TargetDay + 7-datepart(dw, getdate())) % 7, getdate())

TargetDay must be supplied as an integer, according to the settings of your @.@.DATEFIRST property. Normally, Sunday = 1, Monday = 2, etc.

Also, this returns 0 if the today is the TargetDay. Not sure exactly what you wanted in that case...|||Thx a lot lindman and bill..