How connect to MS SQL Server
Hi to All,
this is my scenario.
I have in my LAN two Server; on the first server exist a Web ASP Application based on MS SQL Server DB.
On the second Server I have Oracle DB 10g and AS Forms and Reports.
Can I install on the second server only the run-time of SQL Server that point to remote DB ton the First Server, in order to connect Oracle DB to SQL DB through HS?
Thank You and Best Regards
Gaetano
no need to install SQL Server runtime.
HSODBC uses the SQL Server ODBC which is part of the MDAC or even on newer OSes part of the OS itself.
So if the Oracle db is running on Windows 32bit just go ahead with the HSODBC configuration. A document how to do this can be found on Metalink.
If your Oracle db runs on Unix the OS must be AIX, HP-UX RISC, SPARC Solaris or starting with Oracle 10g Linux 32 bit that offers HSODBC support. You will then need a 32bit ODBC driver for SQL Server (for example Data Direct) to establish the connection.
Other possibility would be TG4MSQL which is indepandant from the Oracle AND SQL Server. So you can install it on any 32bit operating system and it can be contacted from any Oracle RDBMS on any platform and will establish connection to SQL Server on any other machine.
Similar Messages
-
How do I create a connection string to sql server?
Hi All,
I am currently connecting to a SQL Server via ODBC DSN connection. I am wondering how do I create a connection string directly to a sql server without a DSN connection?
Thank you in advance.If you have SQL Server or client installed in your machine you can directly connect to SQL server using native connection. When you create new report you can see the option create new connection, here you can see SQL Server. Expand it and enter the connection details where you will be directly connected to SQL Server without ODBC connection.
Regards,
Raghavendra -
How can i connect to a SQL Server 2000 database usgin JSP?
I need (URGENT) to connect to SQL Server 2000 databse using JSP. I do not know how to program using JSP, so if anyone has any code snippet please let me see it. What i need is to give my site some login/password security.
Anyone?
Thx.just create an ODBC of your database from control pannel -> administrative tools -> data sources (ODBC) ,double click it .....
go to the tab SYstem DSN , click on ADD button. select the driver for your connection. it will be the last one in the list "SQL Server".
click Next then give ur DSN name there, description and Server Name , on next give your username and password of SQL server. when it will be connected to the server celect your database from there and hence there will be an ODBC bridge same as in case of MS Access.
code for connecting to ODBC is
// DSN-NAME same as in System DSN.
// username and password are of your databse
try
url = "jdbc:odbc:DSN-NAME";
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
connect = DriverManager.getConnection( url,"username","password" );
catch ( ClassNotFoundException cnfex ) {
setErrorMsg( cnfex.getMessage() );
catch ( SQLException sqlex ) {
setErrorMsg( sqlex.getMessage() );
catch ( Exception ex ) {
setErrorMsg( ex.getMessage() );
Now you are connected to the SQL Server ..... use connect object for further processing ......... -
How to connect to a Sql server from Oracle using db link
Hi All,
Does anybody have any idea about how to connect to a sql server from oracle database using db link to syncronize the data? I need to pull the data from Sql server table to Oracle tables and relay messages back to the sql server.
Thank you,
Praveen.we have 2 products - DG4MSQL and DG4ODBC.
DG4ODBC is for free and requires a 3rd party ODBC driver and it can connect to any 3rd party database as long as you use a suitable ODBC driver
DG4MSQL is more powerfull as it is designed for MS SQL Server databases and it supports many functions it can directly map to SQL Server equivalents - it can also call remote procedures or participtae in distributed transactions. Please be aware DG4MSQL requires a license - it is not for free.
Check out Metalink and you'll find notes how to configure both products.
For a generic overview:
Note.233876.1 Options for Connecting to Foreign Data Stores and Non-Oracle Databases
And the setup notes:
DG4ODBC
Note.561033.1 How to Setup DG4ODBC on 64bit Unix OS (Linux, Solaris, AIX, HP-UX) :
Note.466225.1 How to Setup DG4ODBC (Oracle Database Gateway for ODBC) on Windows 32bit RDBMS.HS-3-2 :
Note.109730.1 How to setup generic connectivity (HSODBC) for 32 bit Windows (Windows NT, Windows 2000, Windows XP, Windows 2003) V817:
Note.466228.1 How to Setup DG4ODBC on Linux x86 32bit
DG4MSQL
Note.466267.1 How to Setup DG4MSQL (Database Gateway for MS SQL Server) on Windows 32bit
Note.562509.1 How to Setup DG4MSQL (Oracle Database Gateway for MS SQL Server) 64bit Unix OS (Linux, Solaris, AIX,HP-UX)
Note.437374.1 How to Setup DG4MSQL (Oracle Database Gateway for MS SQL Server) Release 11 on Linux -
How to connect to ms sql server analysis server
I am interested to learn how to use the sql server olap technology
--can any one help?
and also i need how to connect to the analysis server and get data from the cubes.
is there a demo available...possibly a demo application as well?
or site that shows or uses OLAP technology using java.
thanx in advance
ashokI was thinking about how to achieve that. But I have not found any opensource JDBC driver or package that provides the feature you are looking for.
However there is still a change of building some kind of bridge through web services. You could implement a web service with the .NET framework, exposing whichever you need of MS Analysis service to a Java WS client.
Good luck -
How many users from an application can connect to a SQL server at a time?
HI,
I need to know , How many users from an application can connect to a SQL server at a time? Do we have any settings for this in SQL server for limiting the users?This is a difficult question, since it is both technical and legal.
The absolute maximum number of connections is around 32700, but unless your server is very beefy, it will choke long before that. A connection is not a user - an application can have many connections for the same user. Depending on your license
model, you may be legally limited to a certain number of users, but this number is not enforced technially.
Erland Sommarskog, SQL Server MVP, [email protected] -
How to connect to MS SQL server using JSP?
Hi, i am new to JSP so i would like to know what is the code to create a connection to MS SQL server.
I am using jakarta-tomcat 4 as my server.
sorry for any inconvenient....
pls help me....This works to start off with but there are more sophisticated/ different ways of doing things,for instance it's best not to access the db via your jsp, rather do this logic in JavaBeans, Servlets or use Struts.Therefore, it's best that you consult with others and find out which is best way to go about creating your web apps.
Here's some code:
In my jsp's I access the bean below , instantiate a statement object and go on from there:
*SOME of the code in the JSP's.
//create bean instance
<jsp:useBean id='dbConn' class='projectsevenhouses.DatabaseConnectionBean ' scope='session' />
//instantiate statement
Statement st = dbConn.getConnection().createStatement();
* JavaBean
package projectsevenhouses;
public class DatabaseConnectionBean implements Serializable {
private Connection conn;
private Statement st;
private String dbURL = "jdbc:odbc:datasource";
private static String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
/** Creates a new instance of DatabaseConnectionBean */
public DatabaseConnectionBean() {
makeConnection();
public void setDatabaseName(String dbName) {
dbURL = dbName;
private void makeConnection() {
try {
Class.forName(driver);
conn = DriverManager.getConnection(dbURL,"sa","");
} catch (SQLException e) {
System.out.println("SQL Cause ->" + e.toString());
} catch (ClassNotFoundException cnf) {
System.out.println("Class Not Found:" + cnf);
public Connection getConnection() {
if (conn == null) {
makeConnection();
return conn;
public void setCloseConnection(boolean close) {
if (close) {
try {
conn.close();
} catch (Exception e) {
conn = null;
Hope it gives u an idea...
Ciao
Ushanta -
Local Network Connection Problem with SQL Server 2008 R2
Hi,
I have CRM application which uses SQL server 2008. Weird thing is that I have no problems connecting from client machines to the server when using a particular router (via LAN) and when I upgrade the firmware of the same router (A common open source firmware
which is used by many also works perfect apart from mentioned problem) and restart the server, the connection cannot be established. I get Error 40.
When i downgrade the firmware and restart the server, the connection works again.
Please note that I am absolutely not touching any configuration of the server. Also the CRM software allows remote connections from public IPs which this feature works fine with both downgraded and upgraded firmwares.
As for my understanding, the routers do not block ports in LAN connections. So how can I diagnose the reason for this connection problem?Hi Leony83,
Please also help to check Windows Event Log information regarding this issue, so that we can do further investigation. In additin, here is the general steps to troubleshoot SQL Server Error 40 issue. Please see:
SQL SERVER – Fix : Error : 40 – could not open a connection to SQL server – Fix Connection Problems of SQL Server:
http://blog.sqlauthority.com/2008/08/24/sql-server-fix-error-40-could-not-open-a-connection-to-sql-server-fix-connection-problems-of-sql-server/
Hope this helps.
Regards,
Elvis Long
TechNet Community Support -
Java Concurrent Program - connecting to MS SQL Server
Hi,
I hope this is correct forum to post this question.
I am writing a JCP which will connect to a MS SQL Server DB, pull data from a table and populate this data into a custome table in EBS (R12.1.1) database. But I am facing some issues.
When I run run this concurrent program from EBS, I get following exception message:
Wed Aug 08 01:18:04 GMT 2012: In openConection()
Wed Aug 08 01:18:04 GMT 2012: Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver
Wed Aug 08 01:18:04 GMT 2012: openConection() ClassNotFoundException: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
Wed Aug 08 01:18:04 GMT 2012: Before Calling processPrintMachineRecords()
Wed Aug 08 01:18:04 GMT 2012: Exception:: java.lang.NullPointerException
Wed Aug 08 01:18:04 GMT 2012: In closeSQLServerConnection().......closing JDBC Connection
Wed Aug 08 01:18:04 GMT 2012: Connection object was null, hence skipping close
Wed Aug 08 01:18:04 GMT 2012: After Calling processPrintMachineRecords()
The I read somewhere on internet that I should set CLASSPATH in options field of concurrent program definition. So I provided classpath as follows:
-cp /rs01/u02/applmgr/utyeb02/apps/apps_st/appl/au/12.0.0/appsborg.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes/apps.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes/sqljdbc_4.0/enu/sqljdbc.jar
In this classpath sqljdbc.jar contains the classes for connecting to MS SQL Server DB. However after giving classpath like this I started getting different error:
Exception in thread "main" java.lang.NoClassDefFoundError: oracle/apps/fnd/cp/request/Run
Caused by: java.lang.ClassNotFoundException: oracle.apps.fnd.cp.request.Run
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
It appears from the error message that after giving this CLASSPATH, program was not able to find the "Run" method itself. In otherwords, CLASSPATH screwed it further.
Can anybody please point out what am I doing wrong here?
Regards
Java Code:
package oracle.apps.custom.printmachine;
import java.sql.*;
import oracle.apps.fnd.cp.request.* ;
import java.io.*;
import oracle.apps.fnd.util.*;
public class PrintMachineInterface implements JavaConcurrentProgram {
public static final String M_SUCCESS = "SUCCESS";
public static final String M_ERROR = "ERROR";
public static final String M_WARNING = "WARNING";
int mRequestStatus = -1;
int max_number_of_records = 99999999;
private String mSqlServerHost = "mysqlserver.domain.com";
// Application Short Name
private String applName;
CpContext mCtx;
LogFile logFile;
OutFile outFile;
Connection mConn = null;
ReqCompletion lRC;
public PrintMachineInterface(){
// if no parameter value is specified for APPLNAME then use FND
//as default value
applName = "FND";
private void logMessage(String str) {
java.util.Date now = new java.util.Date();
logFile.writeln(now.toString() + ": " + str, LogFile.STATEMENT);
static String mInsertRecord = " Declare " + " BEGIN "
+ " INSERT INTO XXGFN_GBL_CE_PM_STAGE(ID, KEY, FILENAME, PRINTED_AT, CREATED_AT, DOCTYPE, LANGUAGE, OU, TRX_ID, DOC_ID, REQ_ID, TEMPLATE, PAGES, DOC_TEXT, TIMES_RECEIVED)"
+ " VALUES (:1, :2, :3, :4, :5, :6, :7, :8, :9, :10, :11, :12, :13, substr(:14,2000), :15);"
+ " COMMIT;"
+ " END;";
static Connection con = null;
public void openConection() {
logMessage( "In openConection()");
try {
logMessage( "Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "After Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "Attempting to connect to " + mSqlServerHost);
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=sql_user;Password=sql_pwd");
logMessage( "After con assigned from getConnection(jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=pm_dba_access;Password=*****");
} catch (java.lang.ClassNotFoundException e) {
logMessage("openConection() ClassNotFoundException: " + e);
} catch (SQLException ex) {
logMessage("openConection() SQLException: " + ex);
public void closeSQLServerConnection() {
try {
logMessage( "In closeSQLServerConnection().......closing JDBC Connection");
if (con != null)
logMessage( "Con is not null");
con.close();
logMessage( "Con Closed Successfully");
else
logMessage( "Connection object was null, hence skipping close");
} catch (SQLException ex) {
logMessage("SQLException: " + ex);
} catch (Exception ex) {
logMessage("Exception in closeSQLServerConnection() : " + ex);
private void populate_staging_table(
String p_id,
String p_key,
String p_filename,
String p_printed_at,
String p_created_at,
String p_doctype,
String p_language,
String p_ou,
String p_trx_id,
String p_doc_id,
String p_req_id,
String p_template,
String p_pages,
String p_doc_text,
String p_times_received
PreparedStatement lStmt = null;
logMessage("Populating data from PrintMachine history table");
try {
lStmt = mConn.prepareCall(mInsertRecord);
lStmt.setString(1, p_id);
lStmt.setString(2, p_key);
lStmt.setString(3, p_filename);
lStmt.setString(4, p_printed_at);
lStmt.setString(5, p_created_at);
lStmt.setString(6, p_doctype);
lStmt.setString(7, p_language);
lStmt.setString(8, p_ou);
lStmt.setString(9, p_trx_id);
lStmt.setString(10, p_doc_id);
lStmt.setString(11, p_req_id);
lStmt.setString(12, p_template);
lStmt.setString(13, p_pages);
lStmt.setString(14, p_doc_text);
lStmt.setString(15, p_times_received);
lStmt.execute();
lStmt.close();
} catch (SQLException s) {
logMessage("Exception thrown w/ error message: "
+ s.getMessage());
s.printStackTrace();
finally {
try {
if (lStmt != null)
lStmt.close();
} catch (SQLException e) {
logMessage("SQLException: " + e);
private void processPrintMachineRecords() {
int number_of_recs = 0;
try {
PreparedStatement stmt = con.prepareStatement("SELECT TOP 1000 ID, Key, Filename, PrintedAt, CreatedAt, Doctype, Language,OU, TransactionID, DocumentID, RequestID, Template, Pages, Documenttext, TimesReceived FROM PM_DATA.dbo.History" );
ResultSet rst = stmt.executeQuery();
while (rst.next()) {
number_of_recs++;
if (number_of_recs == max_number_of_records) break;
populate_staging_table(
rst.getString(1), rst.getString(2)
,rst.getString(3), rst.getString(4)
,rst.getString(5), rst.getString(6)
,rst.getString(7), rst.getString(8)
,rst.getString(9), rst.getString(10)
,rst.getString(11), rst.getString(12)
,rst.getString(13), rst.getString(14)
,rst.getString(15)
stmt.close();
rst.close();
mConn.commit();
} catch (SQLException ex) {
logMessage("SQLException: " + ex);
catch (Exception ex) {
logMessage("Exception:: " + ex);
closeSQLServerConnection();
public void runProgram(CpContext pCpContext) {
applName = "XXGFN";
String l_file_path = null;
mCtx = pCpContext;
//get handle on request completion object for reporting status
lRC = pCpContext.getReqCompletion();
// assign logfile
logFile = pCpContext.getLogFile();
// assign outfile
outFile = pCpContext.getOutFile();
// get the JDBC connection object
mConn = pCpContext.getJDBCConnection();
l_file_path = ((new File(outFile.getFileName())).getParent() == null ? ""
: (new File(outFile.getFileName())).getParent());
// get parameter list object from CpContext
ParameterList lPara = pCpContext.getParameterList();
while (lPara.hasMoreElements())
NameValueType aNVT = lPara.nextParameter();
if ( aNVT.getName().equals("APPLNAME") )
applName = aNVT.getValue();
/** openConection() Opens the connection to SQL Server Database*/
openConection() ;
logMessage("Before Calling processPrintMachineRecords()");
processPrintMachineRecords();
logMessage("After Calling processPrintMachineRecords()");
try{
setCompletion(ReqCompletion.NORMAL, "Request Completed Normal");
} catch (Exception e) {
setCompletion(ReqCompletion.ERROR, e.toString());
} finally {
pCpContext.releaseJDBCConnection();
* Sets the request completion status based on proper precedence. ERROR >
* WARNING > NORMAL
* @param pStatus
* Status of the request.
* @param pCompletionText
* Request's completion text.
public void setCompletion(int pStatus, String pCompletionText) {
if ((pStatus == ReqCompletion.ERROR)
|| ((pStatus == ReqCompletion.WARNING) && (mRequestStatus != ReqCompletion.ERROR))
|| ((pStatus == ReqCompletion.NORMAL)
&& (mRequestStatus != ReqCompletion.WARNING) && (mRequestStatus != ReqCompletion.ERROR))) {
mRequestStatus = pStatus;
lRC.setCompletion(pStatus, pCompletionText);
}ok
i used Template.java as input
useful MOS:
How To Create a Java Concurrent Program? [ID 827563.1]
Java Concurrent Program FAQ [ID 827575.1]
i used
//goto ms sql server 2008r2
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = java.sql.DriverManager.getConnection(
"jdbc:sqlserver://1.2.3.4:1433;databaseName=test;selectMethod=cursor",
"test", "test");
if(con!=null) System.out.println("Connection Successful!");
}catch(Exception e){
e.printStackTrace();
System.out.println("Error Trace in getConnection() : " + e.getMessage());
}1.2.3.4 - ip of instance with sqlserver2008r2 :)
in your code
>
try {
logMessage( "Before Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "After Loading Driver com.microsoft.jdbc.sqlserver.SQLServerDriver");
logMessage( "Attempting to connect to " + mSqlServerHost);
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=sql_user;Password=sql_pwd");
logMessage( "After con assigned from getConnection(jdbc:microsoft:sqlserver://" + mSqlServerHost + ":1433;User=pm_dba_access;Password=*****");
} catch (java.lang.ClassNotFoundException e) {
logMessage("openConection() ClassNotFoundException: " + e);
} catch (SQLException ex) {
logMessage("openConection() SQLException: " + ex);
>
try my case for Driver and Connection
put result .class file to needed directory
put sqljdbc4.jar to /rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/lib
and for concurrent program option
-classpath /rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/classes:/rs01/u02/applmgr/utyeb02/apps/apps_st/appl/au/12.0.0/appsborg.zip:/rs01/u02/applmgr/utyeb02/apps/apps_st/comn/java/lib/sqljdbc4.jaralso useful mos:
Classpath Setting of Third Party Jar Files in R12 Java Concurrent Program (JCP) [ID 1292694.1] -
Connect to MS SQL Server 2000 data warehouse
Hi,
I use a MS SQL Server 2000 database for my web application where I use JSP. I suppose to create data warehouse using MS SQL Server's Data Transformation Service. But I don't know it's possible to connect to a MS SQL Server's data warehouse using JSP. So I want to know is it possible to connect to data warehouse using JSP and if it is how to do it? Thank you.You can certainly connect to M$ SQL Server using the JDBC driver:
http://www.microsoft.com/downloads/details.aspx?FamilyID=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&displaylang=en
Connecting to a data warehouse is no different from any relational database. (My understanding is that a data warehouse usually means a star schema implemented in a relational database.) This will connect you.
If you're not familiar with JDBC, you might need the tutorial:
http://java.sun.com/docs/books/tutorial/jdbc/ -
Connect to MS SQL server from OWB on Linux platform
Hi,
I want to connect to MS SQL server through OWB, on Linux platform.
I suppose I would use JDBC driver, and Heterogeneous services. Is that possible?
I did not see anything on JDBC driver for MS SQL server for Linux platform from Oracle.
Also, I was wondering is Oracle Gateway 10g for Linux a way to connect to MSSQL server?
Any leads would be appreciated.
Thanks
AniHi,
This quite an actual topic for myself, so I decided to take some time to collect some information.
Start at:
* Oracle Generic Connectivity and Oracle Transparent Gateway - http://www.oracle.com/technology/products/gateways/gateways_fov.html
You can use the free Heterogenous Services component named Generic Connectivity for connecting to SqlServer over ODBC. You will need to find (or purchase?) a third-party ODBC driver for SqlServer for Linux, e.g. from www.datadirect.com. Setting this up will allow you to define a databaselink to the SqlServer. Open Gateways implements a limited set of the oracle SQL, so you will have to find out what is possible and what not.
See also:
* How To Setup HSODBC on Linux - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=264567.1
* Generic Connectivity Available on Linux x86 with 10g - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=261726.1
You can also use the Transparent Gateway for SqlServer (HS), which is about EURO 12000 per computer(!). This gives you a full implementation of Oracle SQL and you can access the SqlServer like it was Oracle.
You can also install Microsofts JDBC drivers into Oracle's JVM, and connect through JDBC to SqlServer. This is however not supported by Oracle, but it will work. See:
* What is required for a Java Stored Procedure to connect to a SQL Server Database? - https://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_database_id=NOT&p_id=276167.1
See also:
* Options for Connecting to Foreign Data Stores and Non-Oracle Databases - https://metalink.oracle.com/metalink/plsql/showdoc?db=NOT&id=233876.1
* JDBC Developer's Guide - http://download-west.oracle.com/docs/cd/B14117_01/java.101/b10979/overvw.htm
Good luck, Erik Ykema -
Oracle 10.2 on AIX -- need to connect to remote SQL server by dblink
oracle 10.2 on AIX -- need to connect to remote SQL server by dblink
i didn't see a odbc diectory in our oracle home path. how do i know odbc driver is installed in the oracle on our AIX server.
If it is there, do i just need to modify the odbc.ini and then the inithsodbc.ora, linster.ora, tnsnammes.ora files, or am I missing something
Appreciate your response
Edited by: user10876711 on May 12, 2011 9:18 AM
Edited by: user10876711 on May 12, 2011 9:18 AMwhen you want to connect from Oracle to a SQl Server you need the Oracle Gateway (HSODBC or even better Dg4ODBC) and a FOREIGN ODBC DRIVER for your foreign database - a SQL Server ODBC driver. You have to get this driver from a 3rd party vendor - Oracle does not offer any foreign ODBC drivers.
So before being able to use DG4ODBC/HSODBC you need to install from a 3rd paryt vendor a SQL Server ODBC driver. Commercial vendrs are for example Data Direct, Openlink or Easysoft.
On Unix ODBC drivers commonly also require a driver manager. If the ODBC driver vendor does not ship one with the ODBC driver you can get it from www.unixodbc.org -
Best practise for creating an application that connects to a SQL Server database
I have created an application that connects to a SQL Server database and views information using a datagrid and performs several updates when a button
is selected.
I have created a SQLcontrol.vb using the following code:
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class SQlControl
'connection 1
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
Public sqlcmd As SqlCommand
Public sqlda As SqlDataAdapter
Public sqldataset As DataSet
Public Function hasconnection() As Boolean
Try
SQLCon.open()
SQLCon.close()
Return True
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
Public Sub runquery(query As String)
Try
SQLCon.Open()
sqlcmd = New SqlCommand(query,
SQLCon)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon.State
= ConnectionState.Open Then
SQLCon.Close()
End If
End Try
End Sub
Public Sub runquery1(query As String)
Try
SQLCon1.Open()
sqlcmd = New SqlCommand(query,
SQLCon1)
'LOAD
SQL RECORDS FOR DATAGROD
sqlda = New SqlDataAdapter(sqlcmd)
sqldataset = New DataSet
sqlda.Fill(sqldataset)
BH READ DIRECTLY FROM THE DATABASE
'Dim
R As SqlDataReader = sqlcmd.ExecuteReader
'While
R.Read
'MsgBox(R.GetName(0)
& ": " & R(0))
'End
While
SQLCon1.Close()
Catch ex As Exception
MsgBox(ex.Message)
'will
close connection if still open
If SQLCon1.State
= ConnectionState.Open Then
SQLCon1.Close()
End If
End Try
End Sub
End Class
A code for one of my button which views displays data grid contains the following code:
Private Sub Button1_Click_1(sender As Object,
e As EventArgs) Handles Button1.Click
If SQL.hasconnection
= True Then
SQL.runquery("select
* from tablea")
If SQL.sqldataset.Tables.Count
> 0 Then
DGVData.DataSource = SQL.sqldataset.Tables(0)
End If
End If
End Sub
I am fairly new to vb.net and have read a few books and followed a few tutorials on youtube, what I would like to know is, are there any disadvantages
to the way I have connected to a SQL database using the SQLControl.vb. A lot of the vb books include data adapter and dataset within the form, I'm not sure if I'm following best practice by have the connection details outside of the form.
My other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter
and dataset. It all works fine but I just wanted to know of any potential issues?
Public SQLCon As New SqlConnection With {.ConnectionString
= "Data Source=;Initial Catalog=;Integrated Security=True"}
'connection 2
Public SQLCon1 As New SqlConnection With {.ConnectionString
= "Data Source;Initial Catalog=;Integrated Security=True"}
ThanksMy other question is, I have created two connections in the SQLControl and call these connections within the same form using the same data adapter and dataset. It all works fine but
I just wanted to know of any potential issues
1) You are not using Sepration of concerns for a solution that is doing data access, like using a DAL.
http://en.wikipedia.org/wiki/Separation_of_concerns
2) You are directly issuing SQL commands at the UI, leading to sql injection attacks.
3) You are not using a UI design pattern, which leads you to tightly couple database activity to the UI.
http://www.codeproject.com/Articles/228214/Understanding-Basics-of-UI-Design-Pattern-MVC-MVP
@System243trd, parameters are important to prevent SQL injection attacks (people will insert SQL commands into the database if you do not perform basic checking of what you are passing to the database). If you write a stored procedure try to make
the variables the correct SQL server data type to avoid problems later of people trying to call it directly. Darnold924 is right, I see no code to prevent against SQL injection attacks. In addition, during development in some instances LocalSQLDB
database system is used and during deployment you usually need to use the production SQL server database. Moreover, Linq-to-SQL is used on Windows Phone 8.1 and it is required for phone development later and so I highly recommend learning
it if you plan on developing windows phone applications.
@System243trd, If you want the code for the windows phone app I think it uses the MVVM model or that might be for universal apps or regular windows phone apps. I have been using the windows phone Silverlight pivot or panorama template (it might
be pieces of both). I've already submitted to the windows phone marketplace and it had to go through certification first. I plan on later making an article on it but I need to first fix one or two simple problems I have with it. Here's a link to
the source code if you later want to look at the source code (in vb.net):
https://jeffsblogcodesamples.codeplex.com/downloads/get/1445836
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - Sherlock Holmes. speak softly and carry a big stick - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog
- http://www.computerprofessions.us -
Connection problem to SQL Server 2000
I have a local installation of MSSQL 2000, that doesn't seem to use any port as a listener. when checking the log I can see that even though I said it should use a TCP/IP connection, it says it uses a shared memory (I guess the reason is that the installation I did is not for a server but only for running on my machine).
How can I define through BPEL the connection to this kind of MSSQL? can I define a connection that will run on the named pipes of the SQL server?
Thanks in advance.Hi Ophir,
I tried this exercise of connecting to SQL Server myself via jdbc and I wrote a new section for the developer's guide based on it. It was not completely painless. For your specific question the SQL Server Express install sets up connectivity by either 'shared memory' or 'named pipes' by default, but you can easily add a TCP/IP listener (for me via the SQL Server Configuration Manager), which is mandatory for jdbc access. Please see the section 'TCP Port' below.
Not sure if you have it, I am cutting and pasting from the 10.1.2.0.2 DBAdapter guide:
(Oracle® Application Server Adapters for Files, FTP, Databases, and Enterprise Messaging User's Guide
10g Release 2 (10.1.2))
Using a Microsoft SQL Server Database
When using a Microsoft SQL Server database, follow the database connection steps in Chapter4, "Design Time" and use the following information:
MS JDBC Driver
URL: jdbc:microsoft:sqlserver://localhost\NAME:1433;SelectMethod=cursor;databasename=???
Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriver
Driver Jar: .\SQLServer2000\msbase.jar, msutil.jar, mssqlserver.jar
DataDirect Driver
URL: jdbc:oracle:sqlserver://localhost
Driver Class: com.oracle.ias.jdbc.sqlserver.SQLServerDriver
Driver Jar: .\DataDirect\YMbase.jar, YMoc4j.jar, YMutil.jar, YMsqlserver.jar
Note the following when connecting to a SQL Server database:
User name and password
o
SQL Server 2005 installs with Windows authentication as the default. Therefore, you do not log in with a user name and password; rather, your Windows user account either has privilege or does not. JDBC requires you to provide a user name and password.
According to support.microsoft.com, "Microsoft SQL Server 2000 driver for JDBC does not support connecting by using Windows NT authentication." See
http://support.microsoft.com/default.aspx?scid=kb;en-us;313100
However, the DataDirect driver specification states that it does.
If you use your Windows user name and password, you may see something like the following:
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user
'DOMAIN\USER'. The user is not associated with a trusted SQL Server
connection.[Microsoft][SQLServer 2000 Driver for JDBC]
An error occured while attempting to log onto the database.
You must select mixed mode authentication on a clean installation.
o
On a Microsoft SQL Server 2000 Express Edition installation, the system username is su and the password is whatever you provide.
Connect string
From the sqlcmd login, you can infer your connect string, as in the following examples:
Example 1:
sqlcmd
1>
jdbc:microsoft:sqlserver://localhost:1433
Example 2:
sqlcmd -S user.mycompany.com\SQLExpress
1>
jdbc:microsoft:sqlserver://user.mycompany.com\SQLExpress:1433
Example 3:
sqlcmd -S user.mycompany.com\SQLExpress -d master
1>
jdbc:microsoft:sqlserver://user.mycompany.com\SQLExpress:1433;databasename=
master
A full URL is as follows:
jdbc:microsoft:sqlserver://serverName[\instanceName]:tcpPort[;SelectMethod=cursor][;databasename=databaseName]
Database name
If you must explicitly supply the database name, but do not know it, go to
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
If you see a file named master.mdf, then one of the database names is master.
TCP port
Make sure that SQL Server Browser is running and that your SQL Server service has TCP/IP enabled and is listening on static port 1433. Disable dynamic ports. In SQL Native Client Configuration/Client Protocols, make sure that TCP/IP is enabled and that the default port is 1433.
JDBC drivers
You must download the JDBC drivers separately. From www.microsoft.com, click Downloads and search on jdbc. You can also try using the DataDirect driver.
Thanks
Steve -
User objects didn't display in SQL developer connecting to MS SQL server
I follow the document steps and successfully connected to MS SQL server. I can connect and see all the objects in MS SQL if I use the SQL account with sysadmin role. Everything works fine for using the MS SQL account with sysadmin role.
However, if I use a SQL account that only have db_datareader role only, it connects fine. I can run a select statement to select any dbo tables and get data return, but I can't see any dbo objects list on the left navigator bar. It will be very helpful for users to see the objects and names in the navigator bar.
Is there anything special I have to setup in order for the objects to display in the navigator bar for MS SQL server with account have db_datareader only?Hi user615547 ,
I do not see a bug logged on this.
The only issue I can remember beyond db_datareader is that you need
-grant view definition to <user>
on SQL Server 2005 to view a stored procedure definition that is not yours. Even if you have execute privilege you may not have view source privilege.
Can your dba illuminate how the database was locked down?
What version of SQL Server are you using ?
Which specific object browsers are failing or, are all the object browsers failing?
Does the database capture correctly? (browse and capture use slightly different queries.) You will need to create a repository on oracle and 'capture' the sql server database).
-Turloch
Maybe you are looking for
-
How to Add a New Tape Drive to Solaris 10
Hi, I have an old DLT4000 tape drive attached to my SunFire V250. As I am starting to fill up the 40GB on that tape drive I have purchased a new SDLT320 and want to replace it with the old DLT4000. I have set the SCSI ID on the back of the unit to th
-
Solution to a Datasheet view in SharePoint 2007 - loads slowly for about 15000 items
Hi Is there a solution for the above issue, I found some sites suggesting to remove a margin in the stylesheet on custom master pages, but this issue occurs in the default.master page. Could someone please help me...what can I do from the front end t
-
Problems? Runing PE 8 in Win 7 64 or 32 bits
Building a new machine and are soon starting to install OS and programs. My question is: should I install Win7 64 bit or 32 bit? I am gona run PE8. Is there a good idea to install 64 bit and try, and if it do´nt work change and install 32 bit,is that
-
hi, it is great that java supports unicode internally, but how do i make unicode characters printable? i have read about 10 pages now and none gives a straight-forward answer.. anyone please know? thanks. -m
-
Distorted audio when exporting to aiff
Hi there, sure someone can help... Im using FCP just to mix audio for an iDVD project. This way: I have e.g. 10 minutes on a slideshow pass and want to mix, say, 2 songs that cover those 10 min. Everything seems to be fine while working. The problem