Debugging vb.net execution of database function call to remote sql server - vb.net

Working in VWD 2010 Express
I have an aspx.vb file with the following connection string:
Protected Function getPasswordLength() As Integer
Dim conn As New SqlConnection("Data Source=localhost;database=MyDB;Integrated Security=true")
Dim cmd As SqlCommand = conn.CreateCommand()
cmd.CommandText = "select dbo.getPWLen() ;"
conn.Open()
getPasswordLength = CInt(cmd.ExecuteScalar())
conn.Close()
End Function
This works when the code is on the web server / which is collocated with the SQLServer.
However, when I want to debug, I have to copy to the server. I would like to be able to "debug in place" on my development machine and only copy files to the production machine periodically. Technically the production machine is not in production at the moment, but that's beside the point.
Anyway, I followed the following instruction: http://weblogs.asp.net/nannettethacker/archive/2008/02/17/creating-a-database-connection-to-a-remote-sql-server-database-within-visual-web-developer.aspx
I can now see the remote database, functions, etc. on the other machine (from the VWD running on the development machine).
However, I thought I should then be able to execute this same code locally on the development machine using ctrl-F5, but I get the following error:
--
**Server Error in '/' Application.
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)**
Should what I'm doing be possible? If so, any ideas what I'm doing wrong?

Make sure your SQL Server is configured to accept remote connections.

Related

How to connect database in vb.net(Database is installed in mixed mode)

I have written the following code to connect database. I'm using visual studio 2010 and sql server R2( Mixed mode authentication). When i debug my code then an error is shown.
The error is "Login failed. The login is from an untrusted domain and cannot be used with Windows authentication."
I think I have to put my userid and password of sql server in the time of create connection but I don't know the coding. So pls help me
'Dim con As New SqlClient.SqlConnection("data source=SOFTSKOOL-PC1;initial catalog=Sonali_Test_July;Integrated Security=True")
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.Connection = con
con.Open()
'con.Close()
Return con
End Function
First of all you have to make sure that the Mixed Autentification is on
See the link
Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;
Trusted Connection
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
Connection to a SQL Server instance
The server/instance name syntax used in the server option is the same for all SQL Server connection strings.
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;
Trusted Connection from a CE device
A Windows CE device is most often not authenticated and logged in to a domain but it is possible to use SSPI or trusted connection and authentication from a CE device using this connection string.
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;
User ID=myDomain\myUsername;Password=myPassword;
Note that this will only work on a CE device.
Connect via an IP address
Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;
User ID=myUsername;Password=myPassword;
DBMSSOCN=TCP/IP is how to use TCP/IP instead of Named Pipes. At the end of the Data Source is the port to use. 1433 is the default port for SQL Server. Read more here.
Enable MARS
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
MultipleActiveResultSets=true;

VB.NET application not using failover partner

I have a VB.NET app that connects to a SQL Server.
We recently added database mirroring in case of a server failure.
Well of course, our SQL Server failed but the VB.NET app is not failing over.
I found that in our code, a failover partner wasn't specified in the connection string so I updated the connection string as follows:
sConnectionString = "Data Source=PROD-SQL;Failover Partner=FAILOVER-SQL;Initial Catalog=DB;User ID=****;Password=******;"
The SqlClient.SqlConnection object accepts this connection string but when I call its .Open() command it fails with the following error:
"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)"
Why is this? Our intranet apps failed over just fine (Classic ASP using DSN-less connections).
Does the application have to make at least one successful initial connection to the primary server before it can failover successfully?
Thanks!
Run this on your principal db
SELECT DB_NAME(database_id) AS 'DatabaseName'
, mirroring_role_desc
, mirroring_safety_level_desc
, mirroring_state_desc
, mirroring_partner_instance
FROM
sys.database_mirroring WHERE mirroring_guid IS NOT NULL;
The value returned in mirroring_partner_instance is the server name that will be used by your connection for failover, not FAILOVER-SQL. FAILOVER-SQL will be used when it first tries to get a connection but cannot contact PROD-SQL. If PROD-SQL is available the failover partner will be set in cache from the sql server value mirroring_partner_instance.
See here for more info: http://blogs.msdn.com/b/spike/archive/2010/12/15/running-a-database-mirror-setup-with-the-sqlbrowser-service-off-may-produce-unexpected-results.aspx

SQL Server 2000 / ODBC - Not associated with a trusted SQL Server connection

I get this error:
ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Here's my code (C#), I'm running this on a local and on a remote machine:
using (OdbcConnection connection = new OdbcConnection("dsn=mydsn"))
{
connection.ConnectionTimeout = 50000;
OdbcCommand command = new OdbcCommand("select * from users", connection);
command.CommandTimeout = 50000;
connection.Open();
OdbcDataReader reader = command.ExecuteReader();
}
DSN details:
name: mydsn
SQL login: mylogin
database: Test
SQL Server Configuration:
security: sql server and windows authentication mode
Whenever I try to use use the login to Management Studio, everything works fine, I can execute queries.
Check the SQL client network utility and list the possible client protocols.
At least two should be enabled (by default):
TCP/IP
Named Pipes
I got rid of this error as soon as I've put TCP/IP first, named pipes second after switching to Windows Authentication only.
However, you may notice, that "trusted SQL Server Connection" usually refers to Windows Authentication only. If I were you, I would check the connection via osql first with your login and pass.
ODBC ALWAYS uses a trusted connection so the user account (on Windows) must have required privileges to access the database.

Why can I connect to sql server 2008 via odbc but not through vb.net code?

I'm supporting an old vb.net program whose database it connected to was moved from SQL Server 2005 to SQL Server 2008. Is there a setting on SQL Server 2008 which will allow ODBC connections to access the database but not allow VB.NET to connect to it programmatically?
the error i keep receiving in the app is:
An error has occurred while
establishing a connection to the
server. When connecting to SQL Server
2005, this failure may be caused by
the fact that under the default
settings SQL Server does not allow
remote connections. (provider: Named
Pipes Provider, error: 40 – Could not
open a connection to SQL Server)
however I can connect to it when I create a system dsn to the sql server instance and through VS2005's Tools >> Connect to Database.
Here is the code I'm using to connect:
dim strC as string
strC = "data source=bob; database=subscribers; user id=bobuser; password=passme"
dim connection as New SqlClient.SqlConnection(strC)
try
connection.open()
catch ex as Exception
msgbox(ex.message)
end try
connection.Close()
There is no such setting but it is possible because: You are able to access your sever via ODBC because using an ODBC DSN creates a sort of local bridge to the server. Trying to connect to the server from VB.NET code with the SqlClient library from a client machine requires your Sql Server to accept remote connections...
Check this MSDN article for help.
In brief:
You need to set Sql Server to allow remote connections
You need to make sure your firewall isn't blocking Sql Server's port(s)
Make sure TCP/IP is enabled as a comm. mechanism for Sql Server
Start > Run > "CLICONFG" (No quotes)
In the SQL Server Client Network Utility, enable Named Pipes over TCP/IP

How to connect to Oracle 10g server from client machines

I have installed Oracle 10g in one of my office's computer. I want to keep this as database server. I am developing a .net project which will communicate with the database server from client machine and from the server machine. I success to communicate with oracle from server machine but not from client machine using the .net project. The connection code is as follows:
Public OraConn As ADODB.Connection
OraConn = New ADODB.Connection
OraConn.Provider = "OraOLEDB.Oracle"
OraConn.ConnectionString = "Data Source=<my_database_name>;User ID=<my_user>;Password=<my_pass>;"
OraConn.Open()
Please tell me step by step procedures how can I connect to my server database from my .net client program resides on client machine ?
Thanks in Advance.
My first thought is to try and ping the port of the db in your server (if you are using windows you can use "telnet ", see that you aren't blocked by any firewall rules in you server.
my second one is "Data Source="
if all fails, try reading this:
http://www.oracle.com/technology/pub/articles/cook_dotnet.html