|
I'm looking for a C# precompiler that let's me embed SQL in my C# programs.
It should have about the same feature set as SQLJ has for Java, e.g.
- statical sql syntax verified at compile time
- support for bind variables
- single row fetches into local variables
Does anybody know of such a product?
Thanks for your feedback.
|
|
|
|
|
RoyceFHi,
I am trying to connect to my (local) server to get a list of databases on that server. It doesn't work when I pass (local) as the server name, but it works if I hardcode in the actual name. My connect string is:
Data Source=(local);Initial Catalog=master;User ID=sa;Password=;Integrated Security=SSPI;
Does anyone know how to get the actual server name?
TIA,
Royce
Strive for Perfection, Achieve Excellence.
|
|
|
|
|
rfickling@iac-online.com wrote:
I am trying to connect to my (local) server to get a list of databases on that server. It doesn't work when I pass (local) as the server name, but it works if I hardcode in the actual name.
Try localhost
The server name will be the same as the machine name, unless you have installed named instances (in which case localhost will probably need to be followed by a slash and the name of the instance)
Might I also suggest that using the sa account, especially with no password, is inviting an attacker to take out your SQL Server. Also, be aware that someone with that kind of access could potentially run something like
xp_cmdshell 'format c: /fs:ntfs /v:0wn3d' And wow! Just look at the amount of free space on the C drive, but hey! Where did my operating system go?
Do you want to know more?
WDevs.com - Member's Software Directories, Blogs, FTP, Mail and Forums
|
|
|
|
|
Thanks, Colin, but that doesn't work either. The resulting error is "SQL Server does not exist or access denied." Yes, I understand how servers get their names. However, the installer (usually our IT people) has a great deal of flexibility in this. We have at least one server named mach_name\mach_name - I don't know why. So to assume that the server will always be named the same as the machine name is asking for trouble. And on the use of the sa account, I am trying to convince people here that this is a risk that we should not take.
Royce
Strive for Perfection, Achieve Excellence.
|
|
|
|
|
select datasource from sysservers
this will give you the data source name.
|
|
|
|
|
Irsh,
What is the connect string for use with this select statement? My problem is connecting to a server that I don't have its name, not getting data from it. The generic server name (local) doesn't always work, so I need the actual server name in order to connect.
Thanks,
Royce
|
|
|
|
|
as for i know, give the name of u r sever like raghu or venu in data source clause
Eg:data source="raghu"
e.veera raghavendra
|
|
|
|
|
One other note... anything done with the SET cannot be part of a procedure. It will actually change the variable until the sql server is restarted or it is changed back using SET variable
Tojamismis
A mind never grows without mistakes and questions.
|
|
|
|
|
I'm trying to select records where a date occurs between today and the end of the current week with Sunday as the last day of the week. I'd do this with the following code:
SET DATEFIRST 1
SELECT * FROM sometable WHERE recordDate BETWEEN GETDATE() AND DATEADD(d, 7 - DATEPART(dw, GETDATE()), GETDATE()))
This works great, except that I need to make a View that returns this recordset. SET DATEFIRST 1 is not valid in CREATE VIEW.
I also tried making a User Defined Function that returns the date at the end of the week using the logic in the second part of the BETWEEN, but the SET DATEFIRST 1 is not valid in the function either.
Anyone know how I can get my intended result -- the date on sunday of the current week?
|
|
|
|
|
DATEFIRST is a server variable, so you can't execute SET on it in any type of procedure. You'll need to either change it separately or you could check with your DBA to see if there is any problem with making the change permanent.
Tojamismis
A mind never grows without mistakes and questions.
|
|
|
|
|
Hi
I have two Classes: Invoice and LineOfInvoice. In class LineOfInvoice I have a field named "line_number". My question is: in a datagrid the user removes line 3 of the invoice. What is the best way to update the line number field of invoice after third line (witch was removed). Line 4 becomes line 3, line 5 becomes line 4, ...
Remove all lines and insert all lines again with the right numbering from datagrid?
update only de rows after the line removed?
Thanks!
|
|
|
|
|
I did something similar to this a while ago.
I just updated the lines after the one that was removed with an SQL like this:
UPDATE [tableName]
SET line = line - 1
WHERE idKey = @idKey
AND line > @removedLine
Hope it helps!
Edbert P.
Sydney, Australia.
|
|
|
|
|
Hello all
i try to insert string with this char ' but the sql condsider it with the sql command an give me an error
Inset into Table (name , email) values ('haytham's',dod@hotmial.com)
Thanks
|
|
|
|
|
use parametrized query, it will work plus it prevents you from SQL injection.
see MSDN[^] for details.
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
Like David said, use parameterised query.
However, if you're not using .Net, then create a function to replace all your single quotes (') to TWO single quotes ('') not a double quote, e.g. haytham's becomes haytham''s.
Hope it helps!
Edbert P.
Sydney, Australia.
|
|
|
|
|
Hi all
I am an experienced VB/COM+ programmer. Now I need to switch to .Net environment. So please help me to clear my doubt on COM+. How can we bring the same functionality of COM+ through VB.Net/C#.Net? In VB we have to develop a DLL and register the same under Component Services, but what about the .Net. Is it too much different? Etc…
Thank You.
|
|
|
|
|
I am trying to update a table in SQL Server 2000 that will be able to have varying column names (based on the user's specifications). I can read the data fine, but I can't add anything to the table. There are spaces in the column name (i.e. "Received By") and when reading I put brackets [] around it and it works. When I am trying to write to the table, I can update the dataset fine, but not the table in SQL Server. I believe it is a problem with my parameter declaration. When I try to save the data, I get the following error:
Line 1: Incorrect syntax near 'varchar'.
My code is as follows (not everything because it is quite lengthy):
Dim custom01 As String 'Contains the name of the column/field
Dim sampleTable As String 'Contains the name of the table within SQL Server
sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect)
With sampleUpdate
With .Parameters
.Add("@" & custom01, SqlDbType.Varchar, 50, custom01)
End With
End With
As I said, I can update the dataset fine, but when I try to up the dataset back into SQL Server, it crashes. Any thoughts would be greatly appreciated.
|
|
|
|
|
ColdWaterBlue wrote:
Dim sampleTable As String 'Contains the name of the table within SQL Server
sampleUpdate = New SqlClient.SqlCommand("UPDATE " & sampleTable & " SET " & custom01 & " = @" & custom01, dataConnect)
Where is the name of your table? You declare a string to hold the table but you did not give any table name to that string variable (according to the code). So your sampleTable variable would contain "" . Try to give your table name and to the sampleTable variable before process the query.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
For simplicity's sake, I did not include most of the code. The "sampleTable" variable is actually a global variable that houses the table name, but I included the Dim statement to show that it was a variable.
|
|
|
|
|
I am using a MS Access Database.
Can anyone suggest some SQL to find the lowest unused number from one a column, say 'Quantity' for example?
Thanks
|
|
|
|
|
pjholliday wrote:
Can anyone suggest some SQL to find the lowest unused number
What do you mean by unused number? Do you mean that the number that is the lowest value in the table. If so, try the following statement:
SELECT * tblTest ORDER BY tblTest.Quantity
The above statement will sort the column Quantity from the lowest value to the highest value (suppose from 0 to 100). Then the first record of your database will be the lowest value.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
What I mean by unused number is for example I have the following numbers in my column
1
2
3
4
6
7
8
I want it to return the value 5 because that is the lowest value that does not appear in the column.
Is it possible to write a query to do that?
|
|
|
|
|
It is, if you have another table with integer values.
The SQL will be like this:
SELECT MIN(tblInteger.Number)
FROM tblInteger
WHERE tblInteger.Number NOT IN
(
SELECT Numbers
FROM tblData
)
tblData will be the table you described while tblInteger will have integer numbers you use.
So far that's the only way I can think of, maybe others can help?
Edbert P.
Sydney, Australia.
|
|
|
|
|
Hi
How can the database can be backup and restore across network in sql server
suji
|
|
|
|
|
The destination should have a share on it for the sql server user.
You need to give more details.
Are you trying to do it through app, query analyzer or mmc?
|
|
|
|