How to publish an asp.net project with a connection to a DB2 database? - asp.net

I'm developing a project in asp.net that contains a connection to a iseries db2 database; locally the project works because I already have the IBM iseries Access for Windows driver installed in the machine where the project is developed, the problem is when I want to publish it on a server, the connection to the database doesn't work, I suppose the error happens beacuse doesn't exist any driver in the server. What can I do to connect the project with the database if I want to host it on a server for example In Microsoft Azure?
Currently the code to connect with the database is similar to this:
string provider = "DataSource=xxx.xxx.xxx.xxx;userid=user;password=pass;";
iDB2Connection cnn = new iDB2Connection(provider);
string sentencia = "select * from DTA.Customer FETCH FIRST 20 ROWS ONLY";
iDB2Command cmd = new iDB2Command(sentencia, cnn );
iDB2DataReader drDB2;
cnn.Open();
drDB2 = cmd.ExecuteReader();
int i = 0;
while (drDB2.Read())
{
//Console.WriteLine(drDB2.GetString(i));
}
drDB2.Close();
cnn.Close();

Related

loop throught data in DSN connection

I set Netsuite (our business management program) up for web service and ODBC connection.
I configure the ODBC in my server to connect to their web service via system DSN and file DSN. I tested the connection with user id and password and it worked.
But now in my VS2013 my ASP.net (VB) page, I can't get to loop through the records in any table:
Dim cn As OdbcConnection
cn = New OdbcConnection("DRIVER=CData ODBC Driver for NetSuite 2015;dsn=odbc1;uid=myemail.com;pwd=mypassword")
cn.Open()
Dim cmdstring33 As String = "select * from CustomList"
Dim cmd33 As New OdbcCommand(cmdstring33, cn)
Dim rds33 = cmd33.ExecuteReader
'While rds33.Read
' Response.Write(rds33("Internalid"))
'End While
cn.Close()
But i get the following error:
ERROR [HY000] An account must be specified in order to login to NetSuite.
in "Dim rds33 = cmd33.ExecuteReader"
But the account works when I test the connection in ODBC administration window
what am I doing wrong?
Thanks for any advice
With the ODBC .NET Managed Provider, you should either specify the DSN you wish to use:
cn = New OdbcConnection("DSN=odbc1")
OR you should specify the ODBC Driver and the connection string:
cn = New OdbcConnection("DRIVER=CData ODBC Driver for NetSuite 2015;accountid=...;password=*****;roleid=3;user=...;version=2013_1")
where you fill in the connection string values based on the documentation provided for the Driver.
*Note that our Drivers (CData software) don't require user/password by default, so you don't need to specify the uid or password when using a DSN.

SignalR SQL backplane not starting in Pre-Production

After 3 days, this problem's doin' my head in.
SignalR is not creating its backplane SQL schema and tables in my pre-prod environment containing a single SQL server + load balanced web servers.
I've checked
WebSockets are installed in IIS
DB access allows table and schema
creation
.Net 4.5 is installed and is being used
Recommended updates are
installed
The steps listed here are complete (with the exception of doing the deployment from Visual Studio - I use MSBUILD to package and then use WebDeploy)
I've piggy backed the SignalR tracing. Only my trace entries are written - nothing from SignalR.
Everything works (including tracing) in my development environment if I build in Release mode.
Here's my tracing-enhanced start-up process
//Step 1: Check tracing works
var trace = GlobalHost.TraceManager["TestTrace"];
trace.TraceInformation("Preparing to start SignalR");
//Step 2: Check DB access rights
var connectionString = ConfigurationManager.ConnectionStrings["SignalR"].ConnectionString;
var schema = Guid.NewGuid().ToString("N");
using (var sqlConn = new System.Data.SqlClient.SqlConnection(connectionString))
{
using (var sqlCmd = new System.Data.SqlClient.SqlCommand())
{
sqlConn.Open();
sqlCmd.Connection = sqlConn;
sqlCmd.CommandText = String.Format("CREATE SCHEMA [{0}]", schema);
sqlCmd.ExecuteNonQuery();
sqlCmd.CommandText = String.Format("SELECT '{0}' AS [Value] INTO [{1}].[ConnectionString]", connectionString, schema);
sqlCmd.ExecuteNonQuery();
}
}
//Step 3: Initialise SignalR
GlobalHost.DependencyResolver.UseSqlServer(connectionString);
app.MapSignalR(); //This is meant to trigger lots of logging.
//Step 4: Confirm we've successfully passed SignalR start-up
trace.TraceInformation("Finished starting SignalR");
Any help would be great. Cheers.
Problem wasn't in the server-side SignalR but in the client-side JavaScript's start-up routine aborting before connecting to the SignalR Hub.
It seems that SignalR doesn't start logging until the first connection is made.
For some reason (as yet unidentified) the SignalR start-up routine was completing in the development environment and aborting in the pre-production code. A possible cause is a different sequence of start-up events when using compressed JavaScript.

Connecting MS SQL DataBase To GODADDY host

I am new to uploading websites online, I have uploaded my website to Godaddy host and run perfectly but i don't know how to connect my MS Sql Data base and how to configure my connection string ! can any one help me or give me a tutorial of how doing this starting from a normal MS sql Database with normal connection string(Local DB and Local connection string) until uploading it online ?
Connecting to a sql server database on go daddy works the same way as connecting to any other Sql Server db from a .Net perspective.
Log in to your go daddy account to get the connection string info. There's even code samples in there for how to configure your connection string.
Alos, here's a link about .net connection strings in general
http://msdn.microsoft.com/en-us/library/jj653752(v=vs.110).aspx
One of the advantages of using MS SQL is that you can use the SqlClient native libraries, which are faster than ODBC, etc.
using System.Data;
using System.Data.SqlClient;
public class Demo {
public DataTable ConnectAndQuery() {
SqlConnection cn = new SqlConnection("Data Source=IP-GOES-HERE;Initial Catalog=YOUR-DATABASE-NAME-HERE;user id=DB-USER-HERE;password=DB-PASS-HERE;Connection Timeout=300");
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM TableName", cn);
DataSet results = new DataSet();
da.Fill(results);
return results;
}
}
I usually store my connection strings in the web.config. There's actually a specific section you can store them in, if you'd like. Here's an example of that:
http://msdn.microsoft.com/en-us/library/dx0f3cf2(v=vs.85).aspx

How to connect to SQL Server database and retrieve data using Razor in WebMatrix?

I am developing a website using WebMatrix in Asp.net. I have downloaded and installed SQL Server . Now I don't know how to create a database in SQL Server and how to connect to it using Razor Syntax/Method.
WebMatrix is easy to connect to SQL Server; there is an old tutorial that can lead you: Connecting to a SQL Server or MySQL Database in WebMatrix.
With regard to create a table in SQL Server, there are books on how to accomplish this task. The easy way is to use SQL Server Management Studio. Googling I have found this tutorial that maybe could help: Creating databases using SQL Server Management Studio Express.
If you want to work in razer and want to connect with data base and retrieve data.
var db = Database.Open("Employee");
var dbCommand = "SELECT * FROM Movies WHERE ID = '1'"; // Select the name where id=1
var row = db.QuerySingle(dbCommand);
if(row != null)
{
var employee_name = row.Name;
}

Execute/Query against SQL Compact 4.0 in ASP.NET

I'm writing a small little utility MVC app and I need to have the ability to execute ad-hoc queries against my one-table SQL Compact 4.0 .sdf file for management (Web Matrix isn't working right for development, and it won't be available on the PC this will ultimately be running on). Using Entity Framework code-first, everything is working fine, but to do an ad-hoc query, I figured I'd need to connect to it the way I would have in the pre-EF days (see below)
cn = new SqlConnection("Data Source=|DataDirectory|LocalScanData.sdf");
SqlCommand cmd = new SqlCommand(query, cn);
if (cn.State != ConnectionState.Open) cn.Open();
if (query.ToUpper().StartsWith("INSERT") || query.ToUpper().StartsWith("UPDATE") || query.ToUpper().StartsWith("DELETE"))
{
TempData["RowsAffected"] = cmd.ExecuteNonQuery();
return RedirectToAction("SQL");
}
else
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
return RedirectToAction("SQL", dt);
}
But when I try that, I get 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). So, the question, is how can I connect to a SQL CE 4.0 database the old fashioned way? I've also tried using System.Data.SqlServerCe but then I get errors that lead me to believe that only works for CE 3.5 databases.
Any help?
It happened to me, too. It is the way the sdf ddbb works, you can't execute a query against that. You have to create dataset, dataadapter and so on.

Resources