Showing posts with label exist. Show all posts
Showing posts with label exist. Show all posts

Thursday, March 22, 2012

Hello,

the examples from MSDN like the following, don't run on my computer. A System.Data.SqlServer don't exist. No SQLCommand Type, no SQLContext.GetCommand Method and so on...

Ist there something wrong with my installation or how do i execute commands
inside a CLR SQL Server Trigger?

Regards,
Markus
Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlServer
Imports System.Data.SqlTypes
Imports System.Text.RegularExpressions

Public Class EmailTrigger

Public Shared Sub EmailAudit()
Dim triggContext As SqlTriggerContext = _
SqlContext.GetTriggerContext()
Dim userName As String
If triggContext.TriggerAction = TriggerAction.Insert Then
Dim sqlComm As SqlCommand = SqlContext.GetCommand()
Dim sqlP As SqlPipe = SqlContext.GetPipe()
sqlComm.CommandText = "SELECT Username from INSERTED"
Dim dataRecord As Object = sqlComm.ExecuteScalar
userName = dataRecord.ToString
If IsValidEMailAddress(userName) Then
sqlComm.CommandText = "INSERT Emails " & _
"VALUES ('" & userName & "')"
sqlP.Send(sqlComm.CommandText)
sqlP.Execute(sqlComm)
End If
End If
End Sub

Public Shared Function IsValidEMailAddress(ByVal email As String) _
As Boolean
Return Regex.IsMatch(email, _
"^([\w-]+\.)*?[\w-]+@.[\w-]+\.([\w-]+\.)*?[\w]+$")
End Function

End Class

It seems that something like this would work:

Dim pipe As SqlPipe = SqlContext.Pipe
Dim sqlcommand As New System.Data.SqlClient.SqlCommand

sqlcommand.CommandText = _
"Update Haushaltshilfe set Wochentag = 'Montag' where Wochentag = 'Dienstag'"
pipe.ExecuteAndSend(sqlcommand)

sqlcommand.CommandText = "Select * from inserted"
pipe.ExecuteAndSend(sqlcommand)

But how do i get the results?

Is it really so that the examples from msdn with System.Data.SQLServer don't work?|||The reason why it's not working for you is because the example you're trying is old, and they have now merged the old SqlServer provider for System.Data.SqlServer with the client side provider and created a new namespace: Microsoft.SqlServer.Server. In addition some of the methods on the SqlContext object have been replaced with properties.
Replace the Import System.Data.SqlServer with Import Microsoft.SqlServer.Server and do an extra import for System.Data.SqlClient. Then in the code where you say GetTriggerContext, use the propery TriggerContext instead. you also need to create a connection: Dim sqlConn as SqlConnection = new SqlConnection("Context Connection=true") and the open the connection. From the connection you can create the command: sqlConn.CreateCommand. Instead of GetPipe you use the Pipe property and finally you call ExecuteAndSend on the Pipe with your command as param.
Niels

|||Thank you very much Niels!
Are there web-pages where the latest changes in VS 2005 and SQL Server are documented?|||You can check Bob B's blog and mine. We're trying keep track of what's changing.

Tuesday, March 6, 2012

.Net App Deployment Scenario: Privileges for Non-Admin Users

My VB.net application manipulates data in a local SQL Express database. When the app is installed, the database does not exist, but it cannot be created at run-time by anyone other than a user with administrator privileges. In addition, the application shares the data stored in SQL with a critical 3rd party component that can only reach the database via named DSN (also not existing prior to installation).

I see my primary SQL security options as being:

(1) Use SQL or Mixed Mode authentication with an admin-level username/password combination, or

(2) Create a db user/group with admin-level privileges and grant membership to all NT authenticated users

Secondary problem: Creating the DSN.

Does it make sense to create a Custom Action (.dll) that is called at the end of the installation process in order to create the database, the user security context and the named DSN?

Am I overlooking some built-in functionality provided by Visual Studio 2005 that will accompish some or all of this for me? I am aware that customizing the 'silent' installation of SQL Express to use a different authentication mode requires manifest tweaking -- I just don't know anything about setting up the appropriate security for this situation. Would you put the db and role creation stuff in a SQL script and execute it post-install?

Thanks in advance for any insight you can provide.

-T

UPDATE

I plan to modify the SQL Express installation to use mixed-mode authentication, then execute code at the tail end of my app install to (a) create the database, (b) create a dbo-level user (and pwd) for the database, and (c) create my DSN (via SQLConfigDataSource API call).

Feel free to respond if you think/know that there is a better solution.

-T

.Net App Deployment Scenario: Privileges for Non-Admin Users

My VB.net application manipulates data in a local SQL Express database. When the app is installed, the database does not exist, but it cannot be created at run-time by anyone other than a user with administrator privileges. In addition, the application shares the data stored in SQL with a critical 3rd party component that can only reach the database via named DSN (also not existing prior to installation).

I see my primary SQL security options as being:

(1) Use SQL or Mixed Mode authentication with an admin-level username/password combination, or

(2) Create a db user/group with admin-level privileges and grant membership to all NT authenticated users

Secondary problem: Creating the DSN.

Does it make sense to create a Custom Action (.dll) that is called at the end of the installation process in order to create the database, the user security context and the named DSN?

Am I overlooking some built-in functionality provided by Visual Studio 2005 that will accompish some or all of this for me? I am aware that customizing the 'silent' installation of SQL Express to use a different authentication mode requires manifest tweaking -- I just don't know anything about setting up the appropriate security for this situation. Would you put the db and role creation stuff in a SQL script and execute it post-install?

Thanks in advance for any insight you can provide.

-T

UPDATE

I plan to modify the SQL Express installation to use mixed-mode authentication, then execute code at the tail end of my app install to (a) create the database, (b) create a dbo-level user (and pwd) for the database, and (c) create my DSN (via SQLConfigDataSource API call).

Feel free to respond if you think/know that there is a better solution.

-T

Sunday, February 19, 2012

.....SQL Server does not exist or access denied .. Help !

3 workstations previously installed and able to access server.
4th workstation am able to map to server access files but when
attempting to log in receive the following error.
EXTERNAL DATABASE OPEN FAILURE
Error: -2147467259[Microsoft][ODBC SQL Server Driver][Shared Memory]SQL
Server does not exist.
The workstation that is unable to connect is running XP SP2, MDAC 2.7..
the difference btwn this and the others is that it is running wireless.
Ruled out wirelss as being the problem because hooked LAN cable and
receive the same error.
Checked that TCP/IP is enabled and port is 1433
Went to Adminstrative Tools ODBC to access server and receive the
following error:
Connection failed
SQLState: '01000'
SQL Server Error: 20
[Microsoft][ODBC SQL Server Driver][TCP/IP
Sockets]ConnectionOpen(PreLoginHandshake()).
Connection failed;
SQLState: '08001'
SQL Server Error:20
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]Encryption support
on SQL Server
Tried some other setting changes as well can someone help.. PLEASE !!
*** Sent via Developersdex http://www.codecomments.com ***
What version of SQL is on your server?
From WS4, try the odbcping.exe utility. YOu can find it on your SQL Server
install media. This will determine if you can make a conn over odbc, and will
confirm the SQL instance responds to the ping...
Also - make sure the XP built in firewall (or other fw sw) is not blocking
comm...
Regards,
ChrisB
MCDBA OCP
www.MyDatabaseAdmin.com
"Jessica McMillan" wrote:

> 3 workstations previously installed and able to access server.
> 4th workstation am able to map to server access files but when
> attempting to log in receive the following error.
> EXTERNAL DATABASE OPEN FAILURE
> Error: -2147467259[Microsoft][ODBC SQL Server Driver][Shared Memory]SQL
> Server does not exist.
> The workstation that is unable to connect is running XP SP2, MDAC 2.7..
> the difference btwn this and the others is that it is running wireless.
> Ruled out wirelss as being the problem because hooked LAN cable and
> receive the same error.
> Checked that TCP/IP is enabled and port is 1433
> Went to Adminstrative Tools ODBC to access server and receive the
> following error:
> Connection failed
> SQLState: '01000'
> SQL Server Error: 20
> [Microsoft][ODBC SQL Server Driver][TCP/IP
> Sockets]ConnectionOpen(PreLoginHandshake()).
> Connection failed;
> SQLState: '08001'
> SQL Server Error:20
> [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]Encryption support
> on SQL Server
> Tried some other setting changes as well can someone help.. PLEASE !!
>
> *** Sent via Developersdex http://www.codecomments.com ***
>

.....SQL Server does not exist or access denied .. Help !

3 workstations previously installed and able to access server.
4th workstation am able to map to server access files but when
attempting to log in receive the following error.
EXTERNAL DATABASE OPEN FAILURE
Error: -2147467259[Microsoft][ODBC SQL Server Driver][Shared Mem
ory]SQL
Server does not exist.
The workstation that is unable to connect is running XP SP2, MDAC 2.7..
the difference btwn this and the others is that it is running wireless.
Ruled out wirelss as being the problem because hooked LAN cable and
receive the same error.
Checked that TCP/IP is enabled and port is 1433
Went to Adminstrative Tools ODBC to access server and receive the
following error:
Connection failed
SQLState: '01000'
SQL Server Error: 20
[Microsoft][ODBC SQL Server Driver][TCP/IP
Sockets]ConnectionOpen(PreLoginHandshake
()).
Connection failed;
SQLState: '08001'
SQL Server Error:20
[Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]Encryption su
pport
on SQL Server
Tried some other setting changes as well can someone help.. PLEASE !!
*** Sent via Developersdex http://www.codecomments.com ***What version of SQL is on your server?
From WS4, try the odbcping.exe utility. YOu can find it on your SQL Server
install media. This will determine if you can make a conn over odbc, and wil
l
confirm the SQL instance responds to the ping...
Also - make sure the XP built in firewall (or other fw sw) is not blocking
comm...
Regards,
ChrisB
MCDBA OCP
www.MyDatabaseAdmin.com
"Jessica McMillan" wrote:

> 3 workstations previously installed and able to access server.
> 4th workstation am able to map to server access files but when
> attempting to log in receive the following error.
> EXTERNAL DATABASE OPEN FAILURE
> Error: -2147467259[Microsoft][ODBC SQL Server Driver][Shared M
emory]SQL
> Server does not exist.
> The workstation that is unable to connect is running XP SP2, MDAC 2.7..
> the difference btwn this and the others is that it is running wireless.
> Ruled out wirelss as being the problem because hooked LAN cable and
> receive the same error.
> Checked that TCP/IP is enabled and port is 1433
> Went to Adminstrative Tools ODBC to access server and receive the
> following error:
> Connection failed
> SQLState: '01000'
> SQL Server Error: 20
> [Microsoft][ODBC SQL Server Driver][TCP/IP
> Sockets]ConnectionOpen(PreLoginHandshake
()).
> Connection failed;
> SQLState: '08001'
> SQL Server Error:20
> [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]Encryption
support
> on SQL Server
> Tried some other setting changes as well can someone help.. PLEASE !!
>
> *** Sent via Developersdex http://www.codecomments.com ***
>

... not in ... what is the fastest way ?

Hi,
i have two tables, each has a columnn called "value". Now i want all
"values" from table_1 which does not exist in table_2. I tried:
select table_1.value from table_1 where not exists (select * from table_2
where table_2.value = table_1.value)
Is this the fastest way (in SQL-Server2000)?
thanks,
HelmutHi Helmut,
Yes.
Make sure there is an index on table2.value.
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"helmut woess" <hw@.iis.at> wrote in message
news:1tm1fparsdfl.w6pfxn05crxk.dlg@.40tude.net...
> Hi,
> i have two tables, each has a columnn called "value". Now i want all
> "values" from table_1 which does not exist in table_2. I tried:
> select table_1.value from table_1 where not exists (select * from table_2
> where table_2.value = table_1.value)
> Is this the fastest way (in SQL-Server2000)?
> thanks,
> Helmut|||Your query just might be the fastest, but compare in Profiler with this one:
select value
from table_1
left join table_2
on table_2.value = table_1.value
where (table_2.value is null)
ML
http://milambda.blogspot.com/|||Am Tue, 3 Jan 2006 01:34:05 -0800 schrieb ML:

> Your query just might be the fastest, but compare in Profiler with this on
e:
> select value
> from table_1
> left join table_2
> on table_2.value = table_1.value
> where (table_2.value is null)
>
> ML
> --
> http://milambda.blogspot.com/
Thanks, i checked it with the profiler and it seems to be nearly indentical
(i have not so much records now). But your query needs some rows more and
has an additional filter, so if the table has millions of records maybe my
way is faster.
bye,
helmut|||Am Tue, 3 Jan 2006 09:36:12 -0000 schrieb Tony Rogerson:

> Hi Helmut,
> Yes.
> Make sure there is an index on table2.value.
I have an index on it - thanks,
Helmut|||Please, let us know when you test it on millions of rows. We'd like to know.
:)
ML
http://milambda.blogspot.com/