How to use a connection string to connect to an odbc - asp.net

Simply put I'm trying to do something like this:
<connectionStrings>
<add name="UCCXConnection" connectionString="DSN=UCCXWALLBOARD;Uid=uccxwallboard;Pwd=whatever;" providerName="System.Data.SqlClient" />
</connectionStrings>
I've copied a normal SqlClient connection string and altered it to the DSN keyword for use with an odbc. Of course this won't work as the DSN keyword is invalid for this kind of connection strings.
What other changes or frameworks are needed to be able to use a connection string to connect to an odbc?

<configuration>
<connectionStrings>
<add
name="ODBCDataConnectionString"
connectionString="Driver=ODBCDriver;server=ODBCServer;"
providerName="System.Data.Odbc"
/>
</connectionStrings>
</configuration>
Source

char ConnStr[256] =
"DRIVER={IBM INFORMIX ODBC DRIVER};SERVER=my_ids_server_name;
DATABASE=my_ids_databasename;HOST=my_host.my_domain.com;
PROTOCOL=onsoctcp;SERVICE=5550;UID=my_username;PWD=my_pwd;";
SQLDriverConnect( hdbc, NULL, ConnStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
FYI:
If 64bit driver then
DRIVER={IBM INFORMIX ODBC DRIVER (64-bit)}
If you are using DSN then
char ConnStr[256] = "DSN=my_dsn_name"

Related

[ASP.NET]-Connection String Manipulation in ApplicationDbContext

I had a challenge today at work (Solved already but I'll like to put it out here maybe there is a better and smarter way of doing it)
I am working on VSTS with git on a project with another developer.
We use different connection strings so what we do is when I pull, I comment his connection string and activate mine.
When he pulls, he comments mine and activates his.
We don't want to create another git-branch.
What is the best way to achieve this?
Here is an instance of how I did it.
Editing my Web.Config file
Note: the names: DefaultConnection, LocalConnection, livedbsource, localdbsource, localMachineName
<connectionStrings>
<!--Live-->
<add name="DefaultConnection" connectionString="Data Source=livedbsource;Initial Catalog=livedbname;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
<!--Dev-->
<add name="LocalConnection" connectionString="Data Source=localdbsource;Initial Catalog=localdbname;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
And for the ApplicationDbContext
static string ServerName = System.Net.Dns.GetHostName();
//setting what connection string to use - tenary operator
static string ConnectionStringID = (ServerName == "localMachineName") ? "LocalConnection" : "DefaultConnection";
public ApplicationDbContext()
: base(ConnectionStringID, throwIfV1Schema: false)
{
}
On Windows 7 and higher, You can get the localMachineName pressing the Windows Logo and searching for System Information, then look for 'System Name'
Here is the YouTube video I did it in Visual Studio 2017 on a live project and it worked.
https://youtu.be/oKg6ewKhkYs

Connection Strings- smarterasp.net

Can anyone help me with this? Ive been getting tons of errors. I know there's probably just a syntax error here somewhere, but I'm not sure if I'm doing it right.
this is the connection string that was given to me by smarterasp: "Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;"
this was my connection string on my local machine:
<connectionStrings> <add name="d_CapstoneEntities1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=WIN-C43BMU8UF5E\SQLEXPRESS;initial catalog=d_Capstone;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
and then I came up with this, but im still getting the error "Keyword not supported: 'data source'."
<add name="d_CapstoneEntities1" providerName="System.Data.EntityClient" connectionString="Data Source=SQL5006.Smarterasp.net;Initial Catalog=DB_9B7F44_capstone;User Id=DB_9B7F44_capstone_admin;Password=YOUR-PASSWORD;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework;"/></connectionStrings>
I used the EF database first btw.

Entity Framework connection string issue

I am receiving the following error which I believe is a problem with my connection string on GoDaddy. I've copied from an example on Stack Overflow, but it doesn't seem to work. The first part of the stack trace that I'm getting is:
[MetadataException: Unable to load the specified metadata resource.]
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String
assemblyName, String resourceName, ICollection`1 uriRegistry,
MetadataArtifactAssemblyResolver resolver) +2184231
I have a solution with only one project and, of course, the edmx is in that project.
Here is my connection string:
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string='
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;'"
providerName="System.Data.EntityClient" />
Could you replace ' with " and try it again?
<add name="FCGUIDE_Entities"
connectionString="
metadata=res://*/CoreModel.csdl|res://*/CoreModel.ssdl|res://*/CoreModel.msl;
provider=System.Data.SqlClient;
provider connection string="
Data Source=susanbfarrar.db.9319451.hostedresource.com;
Initial Catalog=susanbfarrar;
integrated security=False;
multipleactiveresultsets=True;
App=EntityFramework;
User ID=*****;
Password=*****
Database=*****;""
providerName="System.Data.EntityClient" />
You already have Initial Catalog, so remove Database
Password=*****Database=*****;"
Like this -
Password=*****;"

configuring web.config for deployment with GoDaddy hosting

I have the following connection strings in development using visual studio web developer 2010 express:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\BegASPNET\Cheeztest\App_Data\Database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" providerName="System.Data.SqlClient" />
<add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.CheeztestModel.csdl|res://*/App_Code.CheeztestModel.ssdl|res://*/App_Code.CheeztestModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
What do I need to change/delete/keep in order to connect to a GoDaddy account with the following parameters:
Host Name: someresource.com
Database Name: databasedb
Username: databasedb
Password: password
I am hosting on a GoDaddy account that only allows a single MS SQL database. In development I had two separate databases; one was ASPNETDB.MDF and the other was Database.MDF. Do I also need to have two separate databases in the hosted environment?
I forgot to mention that yes, GoDaddy does provide a configuration string. I have been trying for two days to make it work without success which is why I am posting here.
The string provided by GoDaddy is:
Data Source=somesource.com; Initial Catalog=databasedb;User ID=databsedb; Password=password;
Also, if necessary I can upgrade my GoDaddy account and get another database. Which I am willing to do if it will make my life easier.
UPDATE:
I changed connection strings to this:
<add name="ApplicationServices" connectionString="data source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" providerName="System.Data.SqlClient" />
<add name="ConnectionString" connectionString="Data Source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" providerName="System.Data.SqlClient" />
<add name="DatabaseConnectionString" connectionString="Data Source=leqaspnetdb.db.8311806.hostedresource.com;Initial Catalog=leqaspnetdb;User ID=leqaspnetdb; Password=Dan13206" providerName="System.Data.SqlClient" />
<add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.CheeztestModel.csdl|res://*/App_Code.CheeztestModel.ssdl|res:
//*/App_Code.CheeztestModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=leqaspnetdb.db.8311806.hostedresource.com;
Initial Catalog=leqaspnetdb;User ID=leqaspnetdb;Password=Dan13206;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
And I get this error:
Illegal characters in path.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Illegal characters in path.
You can certainly use one database in your hosted environment as long as there are no schema conflicts.
You can have multiple connectionStrings in web.config pointing to the same database.
Here is an example connection string for discountasp.net hosting (sorry have nothing with goDaddy).
<add name="TestDiscountAspNet"
connectionString="Data Source=xxx.discountasp.net;Initial Catalog=SQL2008R2_837232_yyy;
Persist Security Info=True;MultipleActiveResultSets=True;User ID=myUserName;Password=myPassword"
providerName="System.Data.SqlClient"/>
If you still have any problem, please describe what the problem is.
Below is documentation on Godaddy about connecting to its database:
(http://support.godaddy.com/help/article/256/connecting-to-a-microsoft-sql-server-database-using-aspado?locale=en&ci=4606)
This example describes using ASP/ADO to connect to a Microsoft SQL Server Database.
Replace the db_ fields with the information for your database from the Control Panel in your hosting account. For more information, see Locating Your MS SQL Database Connection Strings for more information.
<%
'Sample Database Connection Syntax for ASP and SQL Server.
Dim oConn, oRs
Dim qry, connectstr
Dim db_name, db_username, db_userpassword
Dim db_server
db_server = "whsql01.mesa1.secureserver.net"
db_name = "your_dbname"
db_username = "your_dbusername"
db_userpassword = "your_dbpassword"
fieldname = "your_field"
tablename = "your_table"
connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename
Set oRS = oConn.Execute(qry)
Do until oRs.EOF
Response.Write ucase(fieldname) & ": " & oRs.Fields(fieldname)
oRS.MoveNext
Loop
oRs.Close
Set oRs = nothing
Set oConn = nothing
%>

ASP.NET Attempt to attach auto-named a database failed?

Parser Error Message: An attempt to
attach an auto-named database for file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data\aspnetdb.mdf
failed. A database with the same name
exists, or specified file cannot be
opened, or it is located on UNC share.
Why could this be happening? My connection string doesn't use |DataDirectory|, it is:
<connectionStrings>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>
I get this error when I try to load default.aspx, after installing BugNET.
Apparently, and certainly for some obscure reason. There is a mistery connection string coming from... nowhere.
Problem solved adding a <clear/> tag.
<connectionStrings>
<clear/>
<add name="BugNET" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=dnmain;Integrated Security=True;"/>
</connectionStrings>
file
D:\Projects\Damnation\Damnation.Website\Damnation.Website.Tracker\BugNET_WAP\App_Data**aspnetdb.mdf**
failed.
This is the ASP.NET standard membership system here - not your "regular" database. There must be a second connection string somewhere that references this aspnetdb.mdf and tries to attach it from a file.
Search your solution for this file name - it must be somewhere!

Resources