Android Tutorial Connect Android to MS SQL Server Tutorial

Status
Not open for further replies.
A new more powerful framework is now available: Remote Database Connector.

This tutorial is a follow up to the previous tutorial that explained how to connect to a MySQL database using a PHP web service. This time we will use an ASP.NET web service to connect to a Microsoft SQL Server.

Android cannot directly connect to the database server. Instead we will use HttpUtils to connect to a simple ASP.NET script that will issue the query and return the result as a JSON string.

There are several possible solutions for the web service implementation:
1. Pre-set the possible queries in the ASP script and then choose one of the queries by setting a parameter in the Http request.
2. Pass the query as-is to the database.

While the second solution is more flexible and doesn't require any changes to the ASP.NET script, it can also be more vulnerable to security attacks. For example a hacker can send a "DROP TABLE" query and erase all the data.
Making the database user a "read-only" user will protect this attack.

In this tutorial I will post the ASP.NET script that handles any query and passes it directly to the server. You can of course modify it and make it support only a set of queries.

ASP.NET code:
B4X:
<%@ Page Language="C#"%>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Page_Load(object sender, EventArgs ec)
    {
        using (SqlConnection cn = new SqlConnection("Database=Test1; User Id=UserName; password=Password")) //change as needed
        {
            using (StreamReader sr = new StreamReader(Request.InputStream, Encoding.UTF8))
            {
                Response.ContentType = "text/plain";
                string c;
                c = Request.QueryString["query"]; //for debugging with the browser
                //you can set the query by adding the query parameter  For ex: http://127.0.0.1/test.aspx?query=select * from table1
                if (c == null)
                    c = sr.ReadToEnd();
                try
                {
                    SqlCommand cmd = new SqlCommand(c, cn);
                    cn.Open();
                    SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
                    while (rdr.Read())
                    {
                        Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);
                        for (int i =0;i < rdr.FieldCount;i++)
                        {
                            d[rdr.GetName(i)] = rdr.GetValue(i);
                        }
                        list.Add(d);
                    }
                    JavaScriptSerializer j = new JavaScriptSerializer();
                    Response.Write(j.Serialize(list.ToArray()));
              
                } catch (Exception e)
                {
                    Response.TrySkipIisCustomErrors = true;
                    Response.StatusCode = 500;
                    Response.Write("Error occurred. Query=" + c + "\n");
                    Response.Write(e.ToString());
              
                }
                Response.End();
            }
        }
    }
</script>
This code depends on System.Web.Extensions.dll.
To use this code you should save it as a file with aspx extension and modify the connection string with your values.
You may need to put System.Web.Extensions.dll in the bin folder (you will get a compilation error when the script runs if it is required and missing).
SS-2011-12-11_16.03.27.png


Before trying to connect from the Basic4android program, it is recommended to test that the script is working by calling it from the browser. It will be easier to read the error message this way. To help with debugging you can send the query as a GET parameter (later it will be sent as the payload).
B4X:
http://www.example.com/test1.aspx?query=select * from table_1

SS-2011-12-11_16.11.33.png


Now for Basic4android program:
B4X:
Sub Process_Globals
   Dim ServerUrl As String
   ServerUrl = "http://www.example.com/test1.aspx"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
      HttpUtils.CallbackActivity = "Main"
      HttpUtils.CallbackJobDoneSub = "JobDone"
   End If

   HttpUtils.PostString("Job1", ServerUrl, "SELECT col1, col2 FROM Table_1")
End Sub

Sub Activity_Resume
   If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone (Job As String)
   If HttpUtils.IsSuccess(ServerUrl) Then
      Dim parser As JSONParser
      Dim response As String
      response = HttpUtils.GetString(ServerUrl)
      parser.Initialize(response)
      Dim rows As List
      rows = parser.NextArray

      'work with result
      'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
      For i = 0 To rows.Size - 1
         Log("Rows #" & i)
         Dim m As Map
         m = rows.Get(i)
         Log("col1=" & m.Get("col1")) 'log the values of col1 and col2
         Log("col2=" & m.Get("col2"))
      Next
   End If
   HttpUtils.Complete = False
End Sub
This is the main activity code. Calling HttpUtils.PostString sends the request. When the request completes, Sub JobDone will be executed. After parsing the response with JSON parser we get a List. Each item in the list represents a row in the results set. Each item is a Map with the column names as keys and the db values as values.

When running the example, make sure to check the logs. Errors will be posted there.

The logs after a successful run:
B4X:
** Activity (main) Resume **
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
Rows #0
col1=23
col2=asdasd
Rows #1
col1=12323
col2=dwqd
Rows #2
col1=0
col2=1
Rows #3
col1=0
col2=1
** Service (httputilsservice) Destroy **
 

Attachments

  • MsSQL.zip
    6.3 KB · Views: 3,400
Last edited:

jalle007

Active Member
Licensed User
Longtime User
B4X:
This call cannot work. If you are using the emulator you should use the following address:
10.0.2.2:59459

With the device you should use the computer local ip address (use ipconfig to find it).

Thx Erel I switch to real site and its working fine. Irealize its hard to set android working with local site. but its not important now.


SELECT command is ok, but UPDATE not.

I have same problem here.
database is updated when I send query directly from address bar
but NOT when I send it from B4A app.


Changing SPACE with %20 did not .:sign0085:
 

dlcarp

New Member
Connecting to SQL Server

Hi Erel,

Just curious. I recently came across your post on how to connect to an SQL server 2008 database. Since you posted this over a year ago, have you found any more efficient way to connect or is this still about the only (best) way to do a connection?

Thanks,
David
 

schalkgreyling

Member
Licensed User
Longtime User
MS SQL connection problem

Hi all, i am quite new to B4A and has run into a problem i cannot seem to resolve using the forum here. So i am trying to connect a mobile app to SQL Server using the code provided here but cannot get the connection established. I got the sql to display in my browser using asp.net like

[{"ID":"1","Name":"Curtis","Surname":"Cleenverck","Cell_num":"082*** 4548","Email_add":"**@gmail.com","SA_ID":"1"}]

but when running the url in the B4A app im getting an error saying

Error occurred. Query=
System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized


An that the error happend on line 26 which is
"cn.Open();"


Now the obvious thing is that the server did not get the query, but i cannot work out why not.

Here are the asp, and B4A code used.

[ASP]<script runat="server">
protected void Page_Load(object sender, EventArgs ec)
{
using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection("Data Source=VM-ONE;Database=TheITCrowd; User Id=it_crowd; password=1qaz!QAZ")) //change as needed
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream, Encoding.UTF8))
{
Response.ContentType = "text/plain";
String c = HttpContext.Current.Request.Url.Query;
c = c.Replace("?query=", "");
c = c.Replace("%20", " ");

//c = Request.QueryString[""]; //for debugging with the browser
//you can set the query by adding the query parameter For ex: <a href="http://127.0.0.1/test.aspx?query=select" target="_blank">http://127.0.0.1/test.aspx?query=select</a> * from table1
if (c == null)
c = sr.ReadToEnd();
try
{

System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(c, cn);
cn.Open();
System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
while (rdr.Read())
{
Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);
for (int i =0;i < rdr.FieldCount;i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);
}
list.Add(d);
}
System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));

} catch (Exception e)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 500;
Response.Write("Error occurred. Query=" + c + "\n");
Response.Write(e.ToString());

}
Response.End();
}
}
}[/ASP]







And the B4A code

'Activity module
Sub Process_Globals

End Sub

Sub Globals
Dim ServerUrl As String
ServerUrl = "http://192.168.1.21:8123/webform1.aspx"
End Sub

Sub Activity_Create(FirstTime As Boolean)
Dim job1 As HttpJob
job1.Initialize("Job1", Me)

'Send a GET request
job1.PostString(ServerUrl, "select col1,col2 from employees")


End Sub

Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1", "Job2"
'print the result to the logs
Log(Job.GetString)
Case "Job3"
'show the downloaded image
Activity.SetBackgroundImage(Job.GetBitmap)
End Select
Else
Log("Error: " & Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




Please help as i am out of ideas what to do.
Thank you very much for any help:)
 

schalkgreyling

Member
Licensed User
Longtime User
Which error do you get? Try to open this Url with the device browser. Does it work?

Sorry oky so a bit more info about the problem, i ran it in AVD manager but also tested it on my phone,
the error i g3t in ADV manager is :

HTML:
LogCat connected to: emulator-5554
** Activity (main) Create, isFirst = true **


Starting Job: Job1


** Activity (main) Resume **


** Service (httputilsservice) Create **


** Service (httputilsservice) Start **


Error. Url=http://192.168.1.21:8123/webform1.aspx Message=Internal Server Error


Error occurred. Query=


System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized

   at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)

   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)

   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)

   at ASP.webform1_aspx.Page_Load(Object sender, EventArgs ec) in c:\Users\Smegal\documents\visual studio 2012\projects\webapplication3\webapplication3\WebForm1.aspx:line 27
** Service (httputilsservice) Destroy **


----------------------------------------------------------------------------------
Notice that is says "Error occurred. Query="
Meaning that it does not receive the query i assume ?
Since the Query is blank..

When i open my web browser and insert "http://localhost:8123/",
i get the same error, but when i enter in the URL of the web browser
"http://192.168.1.21:8123/webform1.aspx?query=select%20*%20from%20employees"
i get reply

HTML:
[{"ID":"1","Name":"Curtis","Surname":"Cleenverck","Cell_num":"082 672 4548","Email_add":"curtiscleenverck@gmail.com","SA_ID":"1"}]

which is what i need on the mobile side.

Thank you very much for taking time to help me.

here are the code for asp.net
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs ec)
{
using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection("Data Source=VM-ONE;Database=TheITCrowd; User Id=it_crowd; password=1qaz!QAZ")) //change as needed
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream, Encoding.UTF8))
{
Response.ContentType = "text/plain";
String c = HttpContext.Current.Request.Url.Query;
c = c.Replace("?query=", "");
c = c.Replace("%20", " ");

//c = Request.QueryString[""]; //for debugging with the browser
//you can set the query by adding the query parameter For ex: <a href="http://127.0.0.1/test.aspx?query=select" target="_blank">http://127.0.0.1/test.aspx?query=select</a> * from table1
if (c == null)
c = sr.ReadToEnd();
try
{

System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(c, cn);
cn.Open();
System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
while (rdr.Read())
{
Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);
for (int i =0;i < rdr.FieldCount;i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);
}
list.Add(d);
}
System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));

} catch (Exception e)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 500;
Response.Write("Error occurred. Query=" + c + "\n");
Response.Write(e.ToString());

}
Response.End();
}
}
}
</script>
<form id="form1" runat="server">
</form>

and for B4A
Sub Process_Globals
Dim ServerUrl As String
ServerUrl = "http://192.168.1.21:8123/webform1.aspx"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
End If

HttpUtils.PostString("Job1", ServerUrl, "select col1,col2 from employees")
End Sub

Sub Activity_Resume
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone (Job As String)
If HttpUtils.IsSuccess(ServerUrl) Then
Dim parser As JSONParser
Dim response As String
response = HttpUtils.GetString(ServerUrl)
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray

'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("col1=" & m.Get("col1")) 'log the values of col1 and col2
Log("col2=" & m.Get("col2"))
Next
End If
HttpUtils.Complete = False
End Sub
 
Last edited:

schalkgreyling

Member
Licensed User
Longtime User
=D=D=D
Oky so after going back to the tutorial script i found my problem and it works now. Feel so dumb right now :sign0104: me :)

Thank you :icon_clap::icon_clap::icon_clap:
 

altc

New Member
Licensed User
Longtime User
I wonder if this example works only with apache or IIS can use

I am an absolute beginner of android devolopment now i need to connect sql server to basic4android last day i wl try with the code as shown above but it have some errors and also i try to connect sql server using mssql library mssql library got from this website with mssql library some post are there they ask try the code following below for connecting sql server

basic4android code :

Dim a As MSSQL
Dim L As List
a.setDatabase("server ipnumber (not name)","databasename","username","password")
L=a.Query("select * from tablename where keyname='xx'")

but the progrm pause on the line begin with L=a.Query.....

friends any one can other idea to connect sql server pls post

or

Attach a sample webservise file
pls help friends.....

This tutorial is a follow up to the previous tutorial that explained how to connect to a MySQL database using a PHP web service. This time we will use an ASP.NET web service to connect to a Microsoft SQL Server.

Android cannot directly connect to the database server. Instead we will use HttpUtils to connect to a simple ASP.NET script that will issue the query and return the result as a JSON string.

There are several possible solutions for the web service implementation:
1. Pre-set the possible queries in the ASP script and then choose one of the queries by setting a parameter in the Http request.
2. Pass the query as-is to the database.

While the second solution is more flexible and doesn't require any changes to the ASP.NET script, it can also be more vulnerable to security attacks. For example a hacker can send a "DROP TABLE" query and erase all the data.
Making the database user a "read-only" user will protect this attack.

In this tutorial I will post the ASP.NET script that handles any query and passes it directly to the server. You can of course modify it and make it support only a set of queries.

ASP.NET code:
[highlight]
<%@ Page Language="C#"%>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs ec)
{
using (SqlConnection cn = new SqlConnection("Database=Test1; User Id=UserName; password=Password")) //change as needed
{
using (StreamReader sr = new StreamReader(Request.InputStream, Encoding.UTF8))
{
Response.ContentType = "text/plain";
string c;
c = Request.QueryString["query"]; //for debugging with the browser
//you can set the query by adding the query parameter For ex: http://127.0.0.1/test.aspx?query=select * from table1
if (c == null)
c = sr.ReadToEnd();
try
{
SqlCommand cmd = new SqlCommand(c, cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
while (rdr.Read())
{
Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);
for (int i =0;i < rdr.FieldCount;i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);
}
list.Add(d);
}
JavaScriptSerializer j = new JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));

} catch (Exception e)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 500;
Response.Write("Error occurred. Query=" + c + "\n");
Response.Write(e.ToString());

}
Response.End();
}
}
}
</script>
[/highlight]
This code depends on System.Web.Extensions.dll.
To use this code you should save it as a file with aspx extension and modify the connection string with your values.
You may need to put System.Web.Extensions.dll in the bin folder (you will get a compilation error when the script runs if it is required and missing).
SS-2011-12-11_16.03.27.png


Before trying to connect from the Basic4android program, it is recommended to test that the script is working by calling it from the browser. It will be easier to read the error message this way. To help with debugging you can send the query as a GET parameter (later it will be sent as the payload).
B4X:
http://www.example.com/test1.aspx?query=select * from table_1

SS-2011-12-11_16.11.33.png


Now for Basic4android program:
[highlight]
Sub Process_Globals
Dim ServerUrl As String
ServerUrl = "http://www.example.com/test1.aspx"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
End If

HttpUtils.PostString("Job1", ServerUrl, "SELECT col1, col2 FROM Table_1")
End Sub

Sub Activity_Resume
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone (Job As String)
If HttpUtils.IsSuccess(ServerUrl) Then
Dim parser As JSONParser
Dim response As String
response = HttpUtils.GetString(ServerUrl)
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray

'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
Log("col1=" & m.Get("col1")) 'log the values of col1 and col2
Log("col2=" & m.Get("col2"))
Next
End If
HttpUtils.Complete = False
End Sub
[/highlight]
This is the main activity code. Calling HttpUtils.PostString sends the request. When the request completes, Sub JobDone will be executed. After parsing the response with JSON parser we get a List. Each item in the list represents a row in the results set. Each item is a Map with the column names as keys and the db values as values.

When running the example, make sure to check the logs. Errors will be posted there.

The logs after a successful run:
[highlight]
** Activity (main) Resume **
** Service (httputilsservice) Create **
** Service (httputilsservice) Start **
Rows #0
col1=23
col2=asdasd
Rows #1
col1=12323
col2=dwqd
Rows #2
col1=0
col2=1
Rows #3
col1=0
col2=1
** Service (httputilsservice) Destroy **
[/highlight]
 

Peekay

Active Member
Licensed User
Longtime User
VB script

Your first piece of code (script) is in C#. Can you possibly let me have it in VB.
Thanks
 

altc

New Member
Licensed User
Longtime User
Error access Sql Anywhere

I send "http://localhost/dbremoto.asmx?query=select codigo,nome from acadclie", for the browser and the data return ok normally.

When I try exec the code bellow, the error occurs.

Error. Url=http://localhost/dbremoto.aspx Message=org.apache.http.conn.HttpHostConnectException: Connection to http://localhost refused

My code
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: SQL Server
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
Dim ServerUrl As String
ServerUrl = "http://localhost/dbremoto.aspx"
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
End If
HttpUtils.PostString("Job1", ServerUrl, "SELECT Codigo, Nome FROM ACadClie")
End Sub

Sub Activity_Resume
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub JobDone (Job As String)
If HttpUtils.IsSuccess(ServerUrl) Then ' the error occurs here
Dim parser As JSONParser
Dim response As String
response = HttpUtils.GetString(ServerUrl)
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray

'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
For i = 0 To rows.Size - 1
Log("Linha #" & i)
Dim m As Map
m = rows.Get(i)
Log("Codigo=" & m.Get("Codigo")) 'log the values of col1 and col2
Log("Nome=" & m.Get("Nome"))
Next
End If
HttpUtils.Complete = False
End Sub
 
Last edited:

altc

New Member
Licensed User
Longtime User
Funcionou acesso ao SQL anywhere

Thangs very much, Erel
I change for 10.0.2.2 then is ok
 

AlteregoHR

Member
Licensed User
Longtime User
Compilation Error



Erel

I have made the aspx file and uploaded it to my website
Changed the login info for the database
Added the BiN folder and System.Web.Extensions.dll it took a couple of different ones to make it run

what about Initial Catalog ????


When i try to run it from a webpage i get


Error occurred. Query=
System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at ASP.test_aspx.Page_Load(Object sender, EventArgs ec) in xxxxxxxxxxxxxxxxx




Thanks


Hello,
I have exactly the same problem.
How did you managed to solve it?
Thanks
 

Kwame Twum

Active Member
Licensed User
Longtime User
Hi I would like to know if it's possible to execute two queries without invoking "Already working. Request ignored". If so, how do I go about it? I want to refresh a view right after inserting new data.
 
Status
Not open for further replies.
Top