on 2017 Feb 21 1:38 AM
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
50 | |
9 | |
8 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.