Executing SQL functions - sql-server

I'm not a programmer, so I need assistance with executing a SQL function in SQL Server 2000.
We have outsourced some work for an iPhone app which uses a web services located where I am. Everything is set-up correctly, but the outsourcing company has asked me to execute an SQL function on the database. I have no idea where to start with this.
This is the email they sent me, I received a txt file with the function in it:
1) Please execute SQL functions in your database that is written in the attached document i.e UDF.txt.
2) Some parameters are added in query string , these are accessed as a parameter in SQL query.
("ShowWhat") = To switch between two SQL query
("latitude") = Latitude
("longitude") = Longitude
("distance") = Distance of KM in which nearby ATM located.
("page") = For which page records user want to see. (Ex: Page 1)
("strPageSize")= Results will be displayed as per size limit parameter for records.

It sounds like you need to run a script against your SQL Server 2000 database.
Find and execute the shortcut for SQL Query Analyzer whereever the SQL Server tools are installed. Likely they're installed on the server loaded with SQL Server 2000.
Connect to the database instance. It could be an IP address or host name. i.e. "localhost"
Change the database using the dropdown in the toolbar. The screenshot below shows master. Change it to whatever target database you want this function created in.
*Open the script your vendor has supplied you by 'opening' the file/script. Alternatively you could copy/paste in the text into a new Query window.
Press F5 to run the script, or click the green triangle in the toolbar.
whatever SQL statements are in the file will be executed. Perhaps it's 1 or more CREATE or ALTER statements.

Related

Connecting to SQL Server in a remote server from Access

We have a Server A and a Server B.
In Server A we have our ERPs made in Access and VBA.
In Server B we have an instance of SQL Server that needs to stay in that server.
Some Access databases need to link to some tables from that SQL Server instance and I don't want the password to be stored in the MSysObjects table, so I cannot manually link the tables checking the save the connection option.
I saved the connection string in a table with password obfuscation. With that connection string I re-link the tables on startup.
The instance is accessed through it's IP, not the name of the instance. If I use the name of the instance it doesn't work.
It works for me but not for other users except one.
The SQL Server instance has been properly configured to allow remote connections, the ports have been opened and rules added to firewall. If it wasn't properly configured it wouldn't work for me and the other user, so I'm pretty confident in that. The same with the connection string and the methods to stablish the connection in Access.
What I've tried:
Installing the SQL Native Client 11.0.
Installing a full SQL Server Express.
Configured the SQL Browser service to star automatically instead of being disabled.
Step 1 did not work for any user. Step 2 did work for one user but not for the rest. Step 3 did not had any effect. For me I had it installed in my machine since forever, so it doesn't apply.
If I try to do the same with a SQL Server instance in our LAN it works for every user, but not when the instance is in a remote server.
Note I have limited knowledge. Maybe I say something that does not make sense.
Ok, a few things:
Installing the SQL Native Client 11.0.
Ok, then you have to re-link the tables - choose the new driver. A refresh of the linked tables is NOT sufficent. And this ALSO means that each work station ALSO now must have native 11 instlled. And if you say decide to link using native 17 (a much newer odbc driver), then AGAIN YOU must install this native driver on each work station. While you can install multiple sql drivers on each workstation, the driver you used to link the tables MUST ALSO be installed and exist on each work station.
Installing a full SQL Server Express.
Why? What would installing a copy of sql server have to do with OTHER sql servers on other machines that you are attempting to connect to? You think installing sql server on a machine effects the sql server running say on amazon.com? So, this move makes no sense at all.
You are attempting to connect to some instance of sql server running on some other computer. Makes no sense nor will it help to install some copy of sql server that you not using, not connecting to, and that has zero to do with this issue.
Configured the SQL Browser service to star automatically instead of being disabled.
Where? The browser service is set to run and startup on the server and SAME machine where sql server is installed and running. So, yes, without question, those two sql servers A, and B most certainly MUST have the sql browser service running. That service is what allows the client computers to connect to that running instance of sql server. In the past, older (previous) versions of sql server would allow a default connection, but now in near all cases, you MUST ensure that the sql browser service is running on that computer that also has the database you are attempting to connect to.
it's worth to note that the instance is accessed through it's IP, not the name of the instance.
No, you likly have this incorrect. There are two part.
The server name - and then the "instance" of sql server running.
While you can swap out (not use) the server name, you STILL WILL NEED to specify the sql server instance.
So, you can use this format:
myservername\SQLEXPRESS
Or, you can replace the server with a IP address, but you STILL NEED the sql server instance. (by default, it is SQLEXPRESS - but you have to check what the instance of sql server database is).
192.168.1.30\SQLEXPRESS
So while you can use IP or server name - it is often more reliable to use the IP address, but that does NOT get you off the hook from having to specify the sql instance you connect to. Again, previous editions of sql server often allowed a "default" instance, and you did not in general have to specify the "instance", but now you do. And to be double clear, when using such a instance, that sql server needs to be running the sql browser service. (in fact, the browser service is what translates the incoming request to the given and correct instance of sql server).
I DON'T want the password to be stored in the MSysObjects table,
You don't have to, and in fact should NOT include the uid/password in your connection string. And in fact ZERO reason exists to do so.
What you do is execute a one time logon, and THEN link the tables without UID/password. This is not only a great idea, but it also means that your uid/password is not included in the connection strings, but also means users can't get at, or even by accident see/get the uid/password.
It also means that say someone where to launch a copy of access, and import the linked tables from this applcation. When they attempt to use the linked tables, they will NOT work.
So, then how do linked tables work without a password? (and this ALSO by the way saves you from having to re-link tables on startup!!!).
The way this works, is you in code execute a one time logon to the server on startup. That means you can either:
Prompt the user for their sql UID/password.
or
Have in code, the uid/password. (or perhaps in a text file y ou read on startup. You can thus hide, or encrypt or whatever for that uid/passwords.
Then in your startup code, you execute a one time logon. Once you done this, then all linked tables will now work - and work without having uid/password.
since you have two servers then you need to execute two logons, one for server A, and one for server B. But, once again, as long as the linked tables exist, then they will work.
Now, there are "longer" articles on how to use this logon idea, and then not have to include, or re-link your tables for the SQL uid/password.
The basic code to execute a logon is like this:
Function TestLogin(strCon As String) As Boolean
On Error GoTo TestError
Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef
Set dbs = CurrentDb()
Set qdf = dbs.CreateQueryDef("")
qdf.connect = strCon
qdf.ReturnsRecords = False
'Any VALID SQL statement that runs on server will work below.
' this does assume user has enough rights to query built in
' system tables
qdf.sql = "SELECT 1 "
qdf.Execute
TestLogin = True
Exit Function
TestError:
TestLogin = False
Exit Function
End Function
Keep in mind, that ONCE you acheived a legal logon, then EVEN addtional logon attempts will return true.
Not usually a big deal, but this means you supply a valid connection to above, and if it logs on and works - then now all your linked tables (without uid/password) will work.
I note the above issue that ONCE you done the logon, then all 2nd or more times running the above will work (even if bad or incorrect!!! - DO NOT forget this tip!!!). (this can confuse the daylights out of a developer, since they execute logon, (or open a table). Then they test above routine with a BAD uid/passwords, and it works!!!
So, you have to EXIT access to clear out the password cache - no other way.
So, keep the above tips in mind.

Access Database - Understand Pass Through

I have been given an Access Database that I have to try to decipher what it is doing.
As a start I see that there is a Pass Through query with a command like:
Exec RefreshGLTableLatestEntries
#sourceDB = 'DB_NAME' ,
#tablePrefix = 'TableName$' ,
#logFile = 'C:\logDB.txt'
When I run it I will get something like:
Result
Success... 108 rows inserted with a total amount of $0.000000
What I don't understand is where are the rows being copied from or copied to.
In the MSSQL database I don't see a table, query, standard procedure or function called 'TableName$'. There are quite a few tables & queries called 'TableName$SomethingElse'. Is there a way to see more details on where is the data coming from?
Similarly, how can I see where are the rows being inserted to? I can not find any file named 'logDB.txt' in my hard disk to see the log. I would suspect that it might not say much more that '...108 rows insterted...'
I'm using:
Access 2016 from Office 365, Version 1609
MS SQL Server Management Studio v17.1
Any ideas on how to get more information on how to get more information on what the Pass Through do?
A Pass-Through query in Access is equivalent to running its SQL code in SQL Server Management Studio.
(In the database that is designated by the connection string of the Pass-Through query.)
The SQL is sent as-is to MSSQL and run there.
RefreshGLTableLatestEntries is the stored procedure that is executed here. You need to locate and analyze it in SQL Server.

Prompt for SQL Server to connect to in Visual Basic 2010

I have a project that current uses a hard coded SQL connection string. I want to make this more flexible so that when I move it to another environment the user can browse for the SQL server to connect to since it will have a different than my test server. I have tried countless ways to Google for a solution and I am just not getting any hit. I am looking for something similar to the open file dialog in VB, except for SQL servers, where it will list all the servers available on the network and let the users select one, then enter credentials.
Does such a thing exist?
Thanks!
It should be easy to develop a dialog box similar to one SQL Server Management Studio uses. Be aware that all instances on the network cannot be enumerated because broadcast packets are not typically routed and due to firewalls so you'll need to allow the user to enter a server name in the combobox. Here's a code snippet to return a DataTable of the found instances (http://msdn.microsoft.com/en-us/library/a6t1z9x2(v=vs.110).aspx):
Dim dt As DataTable = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources
Below is a screenshot of the login dialog from SSMS. Just populate the server name combobox with the server and instance names from the data table, and add the other needed controls.

Job run in sql sever agent insert all null data.

I have a store procedure which insert data into a table in sql. It work find in SQL however when i create a job in sql server management studio to execute this store procedure by
exec store procedure name
the job does run successfully but all the data insert into the table is null.
i have no idea how this happen, please help. Thanks
Part 1:
We need to know more information than what you are supplying.
Here is a list of things to start.
1 - Generate TSQL for the table.
2 - Send us a couple of records to insert.
3 - Sample TSQL code inside the job step.
4 - What account is SQL Agent running under?
5 - Is the job running in the correct database when executing the TSQL statement?
6 - Are there any errors in the job history.
In short, this task can be easily done.
A screen shot or two would be worth a 1000 words!
Part 2:
Please use the snippet tool in windows to grab a screen shot so that I can see what is wrong.
It is very difficult to diagnose things remotely via just words.
Here are some more things to check.
1 - Are you a local admin of the laptop or server?
2 - Make sure you open the SQL server configuration manager as an admin.
This can be accomplished by right clicking the icon and selecting run as an admin instead of a double click to launch.
Below is a sample image of my configuration manager.
Here is the status of my SQL Server agent and the account it is running under.

How to know what application/service is inserting records into a table

Is there a way/method/tool to monitor or to know what application or service is inserting records into a table in ms sql?
If you installed it as part of your SQL Client Tools installation, you can use the SQL Server Profiler tool to perform a trace of the activity taking place on a specific instance of SQL server. This includes capturing the actual sql batches which are inserting the data into your database.
When you setup the trace, select the SQL:BatchStarting(under the TSQL events) and RPC:Starting (under the Store Procedures) events. For each event select the following fields to be included in the trace:
textdata - Will contain the actual query being executed. Look in here for your insert queries.
spid
starttime
application name - Will contain the name of the application on the client if the client is configured with an application name
ClientProcessID - Will contain the process ID of the client application calling SQL Server
DatabaseID
DatabaseName
HostName - Will contain the name of the computer on which the client is running
LoginName - Will contain the login of the user (either the SQL Server or WIndows login)
You can add a filter on either the DatabaseID or DatabaseName fields so the trace only returns events from the database you are interested in tracking down the inserts on.
Additionally, if have an idea about how the insert is being made (for instance a specific storee procedured being called to execute the insert) you can define a filter on the textdata field in the format of %stored_procedure_name% % symbols are wildcards and the text between them represents a porition of the query which is inserting the data.
If you install Microsoft SQL Server Management Studio, the "Activity Monitor" will apparently show you the process name of a given connection (and, e.g., what the last executed statement was).

Resources