Tuesday, March 6, 2012
.NET Complication (CTS)
{
public string name;
public student(string a)
{
name=a;
}
}
what will be the output of the class in cts?As of your declaration -- nothing.
This is just the constructor for the class ?!
HTH, jens Suessmeyer.|||Hello Aditya,
> class student
> {
> public string name;
> public student(string a)
> {
> name=a;
> }
> }
> what will be the output of the class in cts?
If you're asking, "what does an instance of this class look like when I sele
ct
it from a table", that'll depend on the actual data, but it should be a stri
ng
of hexidecimal values.
If you're asking, "what do I get when I declare a T-SQL variable of this
type," you get get nothing because this class doesn't implement the INullabl
e
interface which is required for UDTs in SQL Server 2005.
Otherwise, I'm not clear that you're asking...
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
.Net COM Interop Class not working via sp_OACreate
this thread is actually to help another guy out in a seperate thread lol...I am not a COM expert but I do have a basic understanding of it from a dev perspective. I am trying to get COM interop via VS2005 to work from a sql2005 sp_OACreate call. below is the code. I can replace my custom object with say a sqldmo reference and IT WORKS! So I was thinking maybe security issues, but even when I run sql under an admin account it does not work. and i am connecting via sa for the code.
Also, I have tested the COM object via windows script host/.vbs file: dim oOjbect set oObject = CreateObject(myCOMObject.Math) msgbox oObject.Add(1,1). And the object appears to be listed correctly in the registry under HKEY_Classes
Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Imports Microsoft.VisualBasic
Imports System.Diagnostics
Public Class Math
Public Function Add(ByVal iFirstNum As Integer, ByVal iSecondNum As Integer)
Return (iFirstNum + iSecondNum)
End Function
End Class
DECLARE @.object int
DECLARE @.hr int
DECLARE @.src varchar(255), @.desc varchar(255)
EXEC @.hr = sp_OACreate 'myCOMObject.Math', @.object OUT,5
IF @.hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @.object, @.src OUT, @.desc OUT
SELECT hr=convert(varbinary(4),@.hr), Source=@.src, Description=@.desc
RETURN
END
HI,
I find an extended stored procedure "xp_cmdshell" to create and append the text file from stored procedure. whose example is as given below:
xp_cmdshell "@.ECHO test message >> C:\file.txt"
By using this method currently it seems that my goal can achieve such that i fectch the record and write in the file, but I just want to know how much this extended method is secure to use if i call it from my own DB's stored procedure.
Although, I am also looking forward for the solution of exception by using "OA_Create"
Looking forward for quick response.
Best Regards,
Jawad Naeem
Security risks depends on how the SPs are designed, how users access the SP/SQL Server, your application design (how it calls the SPs etc) among many other things. Generally, xp_cmdshell is a security risk since it can be used to compromise entire server/network/organization if used improperly. This is one of the reasons as part of SQL Server 2005 installation we now disable it by default along with features like CLR, OLE automation SPs etc that allow access to resources outside of SQL Server.
So you need to think about the following: Is it absolutely necessary to create text files from SPs? Why do you need to do that? What purpose does this process serve by creating text files from SPs? It is going to be an inefficient process anyway since you have to do it row-by-row thereby sacrificing performance & scalability. You can do this with few lines of code on the client side or using utilities like BCP without writing any code or SSIS/DTS in an efficient and robust manner.
|||HI,Yes, i know there is security risk to use xp_cmdshell extended SP.
Actualy, the goal which i want to achieve is: A job should run through SQL Server at some specific time like fortnight, which fetches the record from database and write them in a file. So that's why i create a dll in Visual Basic.Net to fetch the record and write them in a txt file. And i write a stored procedure to call the dll. but i am getting an exception as already mentioned in the very first posting of this thread. If i success to remove the exception then i will create a job which runs at some specific time and date and will call my designed stored procedure which will be create to call the dll
so this is my problem and i need its solution badly,
Thanks
Jawad Naeem|||
For your problem, what you are doing seems too complicated. Any reason, why you want to write VB.NET code that runs in the database to extract rows to a file? I am still lost as to purpose of using a SP to call the VB.NET code. You didn't mention the version of SQL Server you are using, running .NET code from the engine is not supported under older versions of SQL Server. See below KB article for more details.
http://support.microsoft.com/default.aspx?scid=kb;en-us;322884
In any case, depending on the file format that you need you just need to create a BCP format file (you may not need one at all) and use BCP to dump data to a file. So you don't really need to write any line of code. You could schedule the BCP using SQLAgent or NT Task Scheduler. You can also write VB Script code in a SQLAgent ActiveScript task or DTS/SSIS package to do the same.
So the answer to your sp_OA* problem is that it is not supported to run .NET code in SQL Server using OLE automation. Using even with xp_cmdshell might be a problem. You will have to try and see. My suggestion would be that you can simplify your implementation and make it more robust by using one of the methods described in the previous paragraph.
|||sorry but he is right...I DID NOT KNOW ABOUT THE CONTENT OF THIS KB article...I guess you can ONLY call TRUE COM objects via sp_OA procs. If your going to leave your database at CompLevel 80 then you must either use a pre.Net COM tool OR use another tier of your application to create/manipulate flat files with..NET class to hold single disconnected record? Nothing smaller than DataSet?
What is the most efficient standalone .NET class that can hold a single disconnected record? The class must also retain column names, but other schema is not relevant (.NET data type is sufficient).
If I understand System.Data.Common.DbDataRecord, it provides an interface on a DbDataReader, and has no storage of its own.
I'm familiar with DataSet, is that the only .NET-standard class to do this?
Thank you,
Shannon
Why not create a normal class with properties and fill it from a SqlDataReader, or use a OR-Mapper..?
|||I second N Frederick 's suggestiong, nothing will be faster (or easier) than a datareader populating a regular class
|||Thanks for your reply. If I understand correctly, you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same.
I'm building a generic server control (an in-place editor with HTML client-side functionality). I just want something to do table-based forms against for now.
My comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they are.
p.s. If you are aware of a free .NET library to do this already, I'm all ears.
TwasBrillig:
you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same
Speaking for myself, I wouldn't overanalyze. The requirement you gave originally is very simple, so solve it with something very simple. OTOH....
TwasBrillig:
comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they
that's a different story, if you don't know at design time what you're getting back then you can't put it in a predefined class. I suspect that your requirements are much more complex than yo've get on![]()
dbland07666:
TwasBrillig:
you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same
Speaking for myself, I wouldn't overanalyze. The requirement you gave originally is very simple, so solve it with something very simple. OTOH...
That's the second cryptic reply that implies in an offhand way that the answer is simple, but doesn't answer. I hear you, the answer is 42. But what does it mean? Sure I'd love to do something very simple; What is very simple to store one record, for goodness sake? A DataSet? That was my question.
dbland07666:
TwasBrillig:
comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they
that's a different story, if you don't know at design time what you're getting back then you can't put it in a predefined class. I suspect that your requirements are much more complex than yo've get on
Not knowing the type is different from not knowing the structure. A record. One table record. Sure I can build a class myself to do it, I can iterate through columns and store Column-name:Object pairs in a dictionary list, and inspect later what type is in the box. No, my requirements aren't more complex. But my question is: Is there a class already in the .NET library to hold one record, one I can copy one record into with a single method call? When I'm done I have one record in storage, and can disconnect my DbDataReader and think about my one record, its columns' values, its columns' data types, and their names for as long as I like?
|||Here are the types in ADO.Net that you can use:
DataSet = Table, rows and columns, a disconnected resultset that more or less reflects a databas but in memory.
DataReader = Need a connection and will read a row on command, so it will only stay at a specific position and move to the next recoed when you ask it to do it. See it as a Row, Column based object.
You can also use DataSet with XML etc.
Then you can create your own classes (custom business objects "entities"), such as a Customer, Product etc.
In your case where you specify that you can't use a custom class, I think you should simply use a DataSet.
|||Thank you Fredrik, that absolutely answered my question. I appreciate you taking your time answering something so basic.
I felt like there must be another class out there that I had overlooked in the library, or some other magic to DbDataRecord that I wasn't aware of.
If I'm not mistaken, I could reliably use DataReader to access the current row after disconnecting it if I only ever asked it for the values, and not any schema information (such as column name or data type).
Thanks again!
.net cf class library commenting problem.
Hi All,
Now I am creating .Net CF2.0 class library project, and I have some public method which take parameters. And I commented those method using following tag.
/// <summary>
///
/// </summary>
/// <returns></returns>
But when I add to other project where I wanted use that dll , when I create instance andcall the method it’s not giving me the description which I gave. But when I refer in the same class library project itself it’s giving outside that it’s not giving the details.
Could you please anyone to solve this problem ?
Thanks ,
Jayakumar a
Hey when you compile the DLL with the above source, compile using /doc switch of CSC.EXE which then generates an XML file.
Place this XML file in the same direction as DLL which you have referenced so that you can see intellisense. Hope this helps!
By the way, this is not the right forum for your question. Please post this type of questions to VS IDE Forums so that you get better answers!
Thanks,
Laxmi
.net and Sql Express
I havn't use replication with express yet, but yu might want to install the sqlnative client onto the client machines. You can get this download from the microsoft downloads site.
|||This particular dll seems to be part of the sdk kit of sql server 2005.
directory 90\SDK\Assemblies
The sql native client did not help. I installed it and still no avail.
How would one deploy the sdk kit files
Cheers
|||Hi Robert,
I'm not clear on why you would want to run your service on a computer that doesn't have SQL Express installed, could you explian? Replication is about communication between two SQL Servers, without a SQL Server, what exactly are you synchronizing?
Thanks for the further detail.
Regards,
Mike
|||hi,
Mike already pointed out there's no real sens in doing what you are trying to do...
are you perhaps trying something already built-in, like Query Notifications? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/querynotification.asp, http://msdn2.microsoft.com/en-us/library/t9x04ed2.aspx
regards
|||I am trying to have one machine that replicates to a internet based server. This one machine is on our local lan. Other users can log into our program which then connects to the local "lan" sql express. Once all work is done, a "On Demand " sync is done. I wrote the dll to perform this on demand sync.I don't want sql express installed on all 10 machines but rather on one lan machine that everyone can use.
Problem is that the dll needs the sql replication dll to function. A machine without sql express installed cannot ask for the sync via the dll.It generates an error
I have tried to include the sql replication dll in my install but it still does not want to work.I think I am registering it wrong.If I install sql express then the dll works.
(I am using VS 2005 .net setup to deploy the project dll.). This is something I am trying to avoid.
At the moment the way it has to work is that everybody does their changes and then requests a sync update from the user, who has the sql express installed, to update the replication.Quite tiresome.
Regards
Robert
|||Robert you answer lies in the application distribution. So this thread should probably be moved to Coding forum.
But anyway. I think your answer lies in remoting, using a multi-tier application.
We have a similar setup where sql exp is used as a server for two or more client applications. You will need to create Data class that run on the machine where SQL Express is installed and then use .Net Remoting from your client machines to invoke the Data class. This centralised data class will be the one that instantiates the SQL replication dll and thus it will call it from it's local machine (The Data Server). For this purpose the data server is just the machine where SQL exp is installed.
There fore the clients need know nothing about SQL Replication only that they create the remoting object and instruct the data class on the server to do the work. Hence they don't need SQL Express installed on every machine.
If you are not familiar with remoting then you will need to do quite a bit of reading up as there can be pitfalls and it may require you application to be restructured completely.
Hope this points you to your answer
Cheers
Rab|||
Just a few question.
Why does the dll not work on its own.
Can I not simply distribute the dll.
I suppose the dll does not contain all the libary files from SQL to invoke the calls made to sql express.
Thanks anyway for the answer.
Cheers
Robert
.net and Sql Express
I havn't use replication with express yet, but yu might want to install the sqlnative client onto the client machines. You can get this download from the microsoft downloads site.
|||This particular dll seems to be part of the sdk kit of sql server 2005.
directory 90\SDK\Assemblies
The sql native client did not help. I installed it and still no avail.
How would one deploy the sdk kit files
Cheers
|||Hi Robert,
I'm not clear on why you would want to run your service on a computer that doesn't have SQL Express installed, could you explian? Replication is about communication between two SQL Servers, without a SQL Server, what exactly are you synchronizing?
Thanks for the further detail.
Regards,
Mike
|||hi,
Mike already pointed out there's no real sens in doing what you are trying to do...
are you perhaps trying something already built-in, like Query Notifications? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/querynotification.asp, http://msdn2.microsoft.com/en-us/library/t9x04ed2.aspx
regards
|||I am trying to have one machine that replicates to a internet based server. This one machine is on our local lan. Other users can log into our program which then connects to the local "lan" sql express. Once all work is done, a "On Demand " sync is done. I wrote the dll to perform this on demand sync.I don't want sql express installed on all 10 machines but rather on one lan machine that everyone can use.
Problem is that the dll needs the sql replication dll to function. A machine without sql express installed cannot ask for the sync via the dll.It generates an error
I have tried to include the sql replication dll in my install but it still does not want to work.I think I am registering it wrong.If I install sql express then the dll works.
(I am using VS 2005 .net setup to deploy the project dll.). This is something I am trying to avoid.
At the moment the way it has to work is that everybody does their changes and then requests a sync update from the user, who has the sql express installed, to update the replication.Quite tiresome.
Regards
Robert
|||Robert you answer lies in the application distribution. So this thread should probably be moved to Coding forum.
But anyway. I think your answer lies in remoting, using a multi-tier application.
We have a similar setup where sql exp is used as a server for two or more client applications. You will need to create Data class that run on the machine where SQL Express is installed and then use .Net Remoting from your client machines to invoke the Data class. This centralised data class will be the one that instantiates the SQL replication dll and thus it will call it from it's local machine (The Data Server). For this purpose the data server is just the machine where SQL exp is installed.
There fore the clients need know nothing about SQL Replication only that they create the remoting object and instruct the data class on the server to do the work. Hence they don't need SQL Express installed on every machine.
If you are not familiar with remoting then you will need to do quite a bit of reading up as there can be pitfalls and it may require you application to be restructured completely.
Hope this points you to your answer
Cheers
Rab|||
Just a few question.
Why does the dll not work on its own.
Can I not simply distribute the dll.
I suppose the dll does not contain all the libary files from SQL to invoke the calls made to sql express.
Thanks anyway for the answer.
Cheers
Robert
.net and Sql Express
I havn't use replication with express yet, but yu might want to install the sqlnative client onto the client machines. You can get this download from the microsoft downloads site.
|||This particular dll seems to be part of the sdk kit of sql server 2005.
directory 90\SDK\Assemblies
The sql native client did not help. I installed it and still no avail.
How would one deploy the sdk kit files
Cheers
|||Hi Robert,
I'm not clear on why you would want to run your service on a computer that doesn't have SQL Express installed, could you explian? Replication is about communication between two SQL Servers, without a SQL Server, what exactly are you synchronizing?
Thanks for the further detail.
Regards,
Mike
|||hi,
Mike already pointed out there's no real sens in doing what you are trying to do...
are you perhaps trying something already built-in, like Query Notifications? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/querynotification.asp, http://msdn2.microsoft.com/en-us/library/t9x04ed2.aspx
regards
|||I am trying to have one machine that replicates to a internet based server. This one machine is on our local lan. Other users can log into our program which then connects to the local "lan" sql express. Once all work is done, a "On Demand " sync is done. I wrote the dll to perform this on demand sync.I don't want sql express installed on all 10 machines but rather on one lan machine that everyone can use.
Problem is that the dll needs the sql replication dll to function. A machine without sql express installed cannot ask for the sync via the dll.It generates an error
I have tried to include the sql replication dll in my install but it still does not want to work.I think I am registering it wrong.If I install sql express then the dll works.
(I am using VS 2005 .net setup to deploy the project dll.). This is something I am trying to avoid.
At the moment the way it has to work is that everybody does their changes and then requests a sync update from the user, who has the sql express installed, to update the replication.Quite tiresome.
Regards
Robert
|||Robert you answer lies in the application distribution. So this thread should probably be moved to Coding forum.But anyway. I think your answer lies in remoting, using a multi-tier application.
We have a similar setup where sql exp is used as a server for two or more client applications. You will need to create Data class that run on the machine where SQL Express is installed and then use .Net Remoting from your client machines to invoke the Data class. This centralised data class will be the one that instantiates the SQL replication dll and thus it will call it from it's local machine (The Data Server). For this purpose the data server is just the machine where SQL exp is installed.
There fore the clients need know nothing about SQL Replication only that they create the remoting object and instruct the data class on the server to do the work. Hence they don't need SQL Express installed on every machine.
If you are not familiar with remoting then you will need to do quite a bit of reading up as there can be pitfalls and it may require you application to be restructured completely.
Hope this points you to your answer
Cheers
Rab
|||
Just a few question.
Why does the dll not work on its own.
Can I not simply distribute the dll.
I suppose the dll does not contain all the libary files from SQL to invoke the calls made to sql express.
Thanks anyway for the answer.
Cheers
Robert
Saturday, February 11, 2012
(system) Variable that holds the record count of a result set?
Hello
is there a variable that is available to me that contains the number
of rows contained in a dataset return from a database call?
have a class that runs a stored proc and returns a dataset/resultset
looking to simply assign an integer this value if it is possible
i'm using (learning) vb.net and sql server
thanks in advance
If you are using a dataset, you can get the number of rows with this syntax:DataSet1.tables(0).rows.count (assuming your Dataset returns only 1 resultset. If you have more than 1, just replace the zero with whatever index you need.)
If you use a DataReader, which tends to be faster, this property is not available, unfortunately.|||
hello. thank you for the reply. that is exactly what i was looking for (DataSet1.tables(0).rows.count). a question about how to reference this from the codebehind...
i have a codebehind that Dims a class, the class returns the dataset, in the codebehind i have a line likeDropDownList1.DataSource = myClass.function1(parm1) to populate the dropdown with the data from the dataset. i get how i could reference this value in the class code, but how would i reference it in the codebehind? is there a way. would i have to do it in the class function and store it in a session variable or something? would be like to reference it directly in the codebehind as that is where i would be using the value.
thanks again.
|||i believe i have figured my question out (yup, i'm new), but if you have any comments i'd appreciate it
instead of directly coding the line as DDL1.DataSource = myClass.function1(parm1)
i modified the code to have...
Dim ds as dataSet = myClass.function1(parm1)
Dim dsCnt as integer = ds.Tables(0).Rows.Count()
DDL1.DataSource = ds
this seemed to get me what i was after. if there is a more efficient or elegant way to do this, i'm all ears![]()
|||The way you've done it is fine. An alternative is to create a property of type dataset in your class, then fill that property in your function. The code behind could then reference your property.
Public Class myClass
Private mMyDataset as dataset
Public Sub New()
MyBase.new()
End Sub
Property MyDataset() As dataset
Get
Return mMyDataset
End Get
Set(ByVal Value As dataset)
mMyDataset = Value
End Set
End Property
Public Sub function1(param) 'can change to a sub since you are filling a property rather than using a return value
myDataset = Database call goes here
End Sub
From your code behind:
dim objClass as new myClass()
with objClass
.function1(param)
DDL1.datasource = .myDataset
DDL1.databind
end with