Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

I am trying to connect sql anywhere12 database to my .net project but while connecting to the database but the connection can not be opened

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using iAnywhere.Data.SQLAnywhere;

namespace myproject1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btncon_Click(object sender, EventArgs e)
        {
         string connetionString = null;
         SAConnection connection = new SAConnection();
         SACommand command;
            //string sqla = null;
         connetionString = " ENG=demo12;UID=dba;PWD=sql;DBN=sql;LINKS=TCPIP";

         //  sqla = "INSERT INTO  Student(Rollnumber,Name) values('" + textBox1.Text + "','" + textBox2.Text + "')";
           // sqla = "SELECT * FROM Contacts";
            connection = new SAConnection(connetionString);
            try
            {
                connection.Open();
                command = new SACommand("SELECT * FROM Contacts", connection);
                command.ExecuteNonQuery();
                command.Dispose();
                connection.Close();
                MessageBox.Show(" ExecuteNonQuery in SqlCommand executed !!");
            }
            catch (Exception )
            {
                MessageBox.Show("Can not open connection ! ");
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

please help me why this things are happening inside the program im just a beginner in sql anywhere

asked 21 Feb '17, 01:38

reebajomon's gravatar image

reebajomon
26113
accept rate: 0%

edited 21 Feb '17, 03:45

Volker%20Barth's gravatar image

Volker Barth
40.2k361550822

There are several questions:
1. Is the program located on the DB server, or not?
2. If not, do you have the network license, or the personal one?

Can you please check this article that describes different scenarios?

(21 Feb '17, 03:16) Vlad
1

In addition to Vlad's suggestions:

  • What native error message do you get? (It should throw an exception of class SAException, which has a Message and NativeError property.)
  • Can you connect successfully with DBISQL to that (demo) database? - I'd highly recommend to become familiar with different connection strings and their effects by using the builtin tools before you start to do database programming yourself...
(21 Feb '17, 03:43) Volker Barth
Comment Text Removed

Your connection string will only connect to a running server ... and it is likely you have additional errors if you have such a server already running.

connetionString = " ENG=demo12;UID=dba;PWD=sql;DBN=sql;LINKS=TCPIP";

will only connect to a server with a "EngineName/ServerName" of 'demo12' and a "DataBaseName" of 'sql'. The latter may also need to be changed to DBN=demo if you have a server running with the sample demo.db running on it.

If you, otherwise, intend to use the SQL Anywhere created sample "Demo" data source you probably should change that to use DSN instead

connetionString = "DSN=SQL Anywhere 12 demo";

If you want to a server to autostart a database that you will need to at least add the DBF= parameter.

permanent link

answered 21 Feb '17, 09:15

Nick%20Elson%20SAP%20SQL%20Anywhere's gravatar image

Nick Elson S...
7.3k35107
accept rate: 32%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×438
×159
×76

question asked: 21 Feb '17, 01:38

question was seen: 2,241 times

last updated: 21 Feb '17, 09:15